Home » Questions » Computers [ Ask a new question ]

MAPI and managed code experiences? [closed]

MAPI and managed code experiences? [closed]

"Closed. This question needs to be more focused. It is not currently accepting answers.












Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 6 years ago.





Improve this question





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)

All I want to do is launch the default e-mail client with subject, body, AND one or more attachments.

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. No, I won't shellExecute Outlook.exe with command line arguments for attachments.

PPS. Attachment support is a requirement , so Mailto: solutions do not cut it for me."

Asked by: Guest | Views: 258
Total answers/comments: 4
Guest [Entry]

"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.

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.

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

"Calling process.Start on the Mailto: protocol (as shown below) will give you basic functionality but not attachments.

Process.Start(""mailto:name@domain.com?subject=TestCode&Body=Test Text"");

You can do this approach with attachment paths but this option only works with some old version of outlook such as 98. I assume this is due to the potential securty risk.

If anyone does use outlook.exe it will give security warnings under outlook 2003 (and 2007 Dependant on settings)."
Guest [Entry]

"MAPISendDocuments is deprecated and might be removed.
You should use MAPISendMail instead.
See Simple MAPI"
Guest [Entry]

You should be able to make an unmanaged DLL that performs the operations you want using MAPI, and then invoke that DLL from your managed code. I wouldn't write a straight MAPI wrapper, but something that performs all of the functionality you require of MAPI contained in that unmanaged DLL. That would probably be the safest way to use MAPI from managed code.