调用olEMail.Send()报错: 0x80004004,网上查了一下,没解决问题。。。
还有就是email是富文本RichText格式的,添加正文附件的位置怎么调整?
求大神指导,代码块如下:
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace nSpace = app.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MailItem olEMail = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Microsoft.Office.Interop.Outlook.Attachments olAttach = olEMail.Attachments;
olEMail.To = "Chun.Xiao.Liu@gds.ey.com";
olEMail.Subject = "TestMail";
olEMail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText;
string stext = string.Empty;
stext += "Adding A1 one more line"+ System.Environment.NewLine;
stext += "Adding A2 one more line"+ System.Environment.NewLine;
stext += "Adding A3 one more line"+ System.Environment.NewLine;
stext += "Adding A4 one more line";
olEMail.Body = stext;
olAttach.Add("C:\\Text\\4.txt", Microsoft.Office.Interop.Outlook.OlAttachmentType.olOLE, stext.IndexOf("A4"));
olAttach.Add("C:\\Text\\3.txt", Microsoft.Office.Interop.Outlook.OlAttachmentType.olOLE, stext.IndexOf("A3"));
olAttach.Add("C:\\Text\\2.txt", Microsoft.Office.Interop.Outlook.OlAttachmentType.olOLE, stext.IndexOf("A2"));
olAttach.Add("C:\\Text\\1.txt", Microsoft.Office.Interop.Outlook.OlAttachmentType.olOLE, stext.IndexOf("A1"));
//olEMail.Display();
olEMail.Send();
olEMail = null;
app = null;