MAPI和管理code的经验?经验、MAPI、code

2023-09-03 03:33:39 作者:空城丶依旧

使用MAPI功能,从内部管理code是官方支持。显然,MAPI使用它自己的内存管理和崩溃,并在管理code烧伤(见的这里和here)

Using MAPI functions from within managed code is officially unsupported. Apparently, MAPI uses its own memory management and it crashes and burns within managed code (see here and here)

所有我想要做的就是启动默认的电子邮件客户端与主题,正文,和一个或多个附件。

所以,我一直在寻找到 MAPISendDocuments 并似乎工作。但我一直没能鼓起勇气实际在生产中使用code的作用。

So I've been looking into MAPISendDocuments and it seems to work. But I haven't been able to gather courage to actually use the function in production code.

有没有人使用这个功能了很多?你有什么恐怖的故事?

Has anybody used this function a lot? Do you have any horror stories?

PS。不,我不会的ShellExecute的Outlook.exe与附件的命令行参数。的

PPS。附件支持是的要求的,所以邮寄地址:解决方案不削减对我来说的

推荐答案

有,做什么是必需的,打电话,从你的主要的应用程序单独的辅助EXE,它采用命令行PARAMS(或管道到StandardInput)。这使MAPI东西,你的主要应用程序的进程空间之外。 OK,你还是混合MAPI和.NET但在一个非常短暂的过程。假设是MAPI和CLR的启动造成的问题与长时间运行的进程。

Have a separate helper EXE that takes command-line params (or pipe to its StandardInput) that does what is required and call that from your main app. This keeps the MAPI stuff outside of your main app's process space. OK, you're still mixing MAPI and .NET but in a very short-lived process. The assumption is that MAPI and the CLR start causing issues with longer-running processes.

我们用梅德Streblechenko的精湛赎回数据对象库,让我们写这样的垫片code JScript中并援用,保持在单独的进程在CLR和MAPI世界,但在支持的方式。

We use Dmitry Streblechenko's superb Redemption Data Objects library which allows us to write such "shim" code in JScript and invoke that, which keeps the CLR and MAPI worlds in separate processes, but in a supported fashion.

@ 克里斯·富尼耶重。写一个非托管的DLL。这是行不通的,因为这个问题是在同一个进程的

@Chris Fournier re. writing an unmanaged DLL. This won't work because the issue is mixing MAPI and managed code in the same process.