Brian
Brian

Reputation:

Wanting to email from C# with attachment like MS Word

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.


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

Upvotes: 0

Views: 1215

Answers (2)

Austin Salonen
Austin Salonen

Reputation: 50245

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.

Upvotes: 0

Michael Petrotta
Michael Petrotta

Reputation: 60972

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.

Upvotes: 2

Related Questions