views:

549

answers:

4

This is really odd that I can't seem to find out how to do this, so I'm wondering if I'm missing something obvious.

I'm wanting to put a menu on our application like is found in Word and Excel, File -> Send To -> Mail Recipient (As Attachment)

Our requirements are to create and display the email with the attachment, just like Word and Excel do, not to send it automatically.

We used to be able to save the file to the temp folder and use: Shell.Execute("mailto:my.email.com?subject=File&attachment="c:\temp.txt");

I've tried the &attach, &attachment in both VB.NET and C# with quotes, double quotes, etc. I've also tried System.Net.Mail but don't see anywhere that you can display the email, it only seems to be able to create and send.

Any help would be much appreciated!

Thanks, Brian

+2  A: 

I've done this using Outlook interop from Visual Studio Tools for Office:

using IntOut = Microsoft.Office.Interop.Outlook;
...
IntOut.Application app = new IntOut.Application();
IntOut.MailItem item = (IntOut.MailItem)app.CreateItem(
                                 IntOut.OlItemType.olMailItem);
item.Subject = "Hello world";
item.Body = "Hello!";
item.Display(false); // set to true to make mail window modal

You can find some samples on MSDN here.

Michael Petrotta
A: 

For the general case, there isn't a way to do this. Here's Microsoft's documentation: http://msdn.microsoft.com/en-us/library/aa767737(VS.85).aspx

If you can provide the mail client, you may get a better answer.

Austin Salonen
A: 

Thanks for the answers, unfortunately we can't use any Outlook references, we have a commercial app and can't include the interop (nor gaurantee it will be installed). I'd like to avoid Outlook references as it makes the code too complex. We can't assume a default email client, it could be Outlook Express, Outlook version 2000, 2003, or 2007, or lotus notes, or ... Don't know. We have a commercial application so I don't think we can assume a specific application. Like MS Word, it needs to work for whatever is installed (or isn't installed).