qq_26624753 2019-05-30 09:39 采纳率: 100%
浏览 1115
已结题

C#操作OutLook发邮件失败

调用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;

就是附件的位置,不好定位

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-05-30 10:05
    关注

    outlook有没有安装好,重新引用下outlook的库,还有,你的系统和你的office还有你的程序的架构要一致,比如都是32bit或者都是64bit

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器