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 = "Anyone@gmail.com";
mailItem.Display(true);
mailItem.Attachments.Add("C:\\File.txt");
}
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 = "Anyone@gmail.com";
mailItem.Attachments.Add("C:\\File.txt");
mailItem.Display(true);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.