通过 C# 使用 CDOSYS 发送已生成的 MHTML?
我有一个已生成的 MHTML 作为字节数组(来自 Aspose.Words),并且想将其作为电子邮件发送。我正在尝试通过 CDOSYS 来做到这一点,但我对其他建议持开放态度。目前,我有以下内容:
CDO.Message oMsg = new CDO.Message();
CDO.IConfiguration iConfg = oMsg.Configuration;
Fields oFields = iConfg.Fields;
// Set configuration.
Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
oField.Value = CDO.CdoSendUsing.cdoSendUsingPort;
oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
oField.Value = SmtpClient.Host;
oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
oField.Value = SmtpClient.Port;
oFields.Update();
//oMsg.CreateMHTMLBody("http://www.microsoft.com", CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
// NEED MAGIC HERE :)
oMsg.Subject = warning.Subject; // string
oMsg.From = "[email protected]";
oMsg.To = warning.EmailAddress;
oMsg.Send();
在此代码片段中,警告变量有一个 Body 属性,它是一个 byte[]。上面代码中写着“NEED MAGIC HERE”的地方我想使用这个 byte[] 来设置 CDO 消息的正文。
我已经尝试了以下方法,不出所料,这不起作用:
oMsg.HTMLBody = System.Text.Encoding.ASCII.GetString(warning.Body);
有人知道如何使用 CDOSYS 或其他东西实现我想要的东西吗?
I have a ready generated MHTML as a byte array (from Aspose.Words) and would like to send it as an email. I'm trying to do this through CDOSYS, though am open to other suggestions. For now though I have the following:
CDO.Message oMsg = new CDO.Message();
CDO.IConfiguration iConfg = oMsg.Configuration;
Fields oFields = iConfg.Fields;
// Set configuration.
Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
oField.Value = CDO.CdoSendUsing.cdoSendUsingPort;
oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
oField.Value = SmtpClient.Host;
oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
oField.Value = SmtpClient.Port;
oFields.Update();
//oMsg.CreateMHTMLBody("http://www.microsoft.com", CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
// NEED MAGIC HERE :)
oMsg.Subject = warning.Subject; // string
oMsg.From = "[email protected]";
oMsg.To = warning.EmailAddress;
oMsg.Send();
In this snippet, the warning variable has a Body property which is a byte[]. Where it says "NEED MAGIC HERE" in the code above I want to use this byte[] to set the body of the CDO Message.
I have tried the following, which unsurprisingly doesn't work:
oMsg.HTMLBody = System.Text.Encoding.ASCII.GetString(warning.Body);
Anybody have any ideas how I can achieve what I want with CDOSYS or something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请不要使用 CDO,它可以追溯到计算机仍然使用烟雾信号来交换电子邮件的时代。 System.Net.Mail 包含您需要的一切,MailMessage 是您的朋友。请注意其 IsBodyHtml 属性。
Please don't use CDO, it dates from an era when computers still used smoke signals to exchange emails. System.Net.Mail contains everything you need, MailMessage is your friend. Note its IsBodyHtml property.
可以通过 CDO.Message (需要添加到项目引用 COM 库“Microsoft CDO for Windows 2000 Library”):
It is possible via CDO.Message (it is necessary add to project references COM library "Microsoft CDO for Windows 2000 Library"):