Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open Outlook's new mail window with prepopulated attachment

I need to open a new email window with a prepopulated attachment when a user clicks some button or link in my application.

like image 551
Selvakumar Avatar asked Sep 11 '12 05:09

Selvakumar


1 Answers

Old question, but I also ran in to this so here's a copy and paste solution:

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

oMsg.Subject = "subject something";
oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
oMsg.HTMLBody = "text body"; //Here comes your body;
oMsg.Attachments.Add("c:/temp/test.txt", Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
oMsg.Display(false); //In order to display it in modal inspector change the argument to true

You'll need to add a reference to the Microsoft.Office.Interop.Outlook component in your project.

like image 133
Pieterjan Spoelders Avatar answered Oct 21 '22 01:10

Pieterjan Spoelders