[英]Sending outlook email with attachment c sharp
I can't get the email to show up with attachment.我无法让 email 出现附件。 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:您需要在调用
Display
方法之前添加附件:
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.