Reputation: 37
I can't get the email to show up with attachment. every thing else works except the attachment. I have tried every thing I can possibly think of and coded it every way I can find online. I'm not sure what I'm doing wrong
public void createEmail(){
Microsoft.Office.Interop.Outlook.Application mailApp = new Microsoft.Office.Interop.Outlook.Application();
MailItem mailItem = mailApp.CreateItem(OlItemType.olMailItem);
mailItem.Subject = "Subject";
mailItem.To = "[email protected]";
mailItem.Display(true);
mailItem.Attachments.Add("C:\\File.txt");
}
Upvotes: 1
Views: 38
Reputation: 49395
You need to add an attachment before calling the Display
method:
public void createEmail()
{
Microsoft.Office.Interop.Outlook.Application mailApp = new Microsoft.Office.Interop.Outlook.Application();
MailItem mailItem = mailApp.CreateItem(OlItemType.olMailItem);
mailItem.Subject = "Subject";
mailItem.To = "[email protected]";
mailItem.Attachments.Add("C:\\File.txt");
mailItem.Display(true);
}
Upvotes: 1