c# - 如何使用 Exchange Web 服务发送包含 text/plain 和 text/html 的多部分电子邮件?

标签 c# exchangewebservices

我通过命令行使用 wsdl 工具生成了一个命名空间,方法是将其指向 https://exchange-server/EWS/Services.wsdl

我能够使用以下代码成功发送电子邮件:

const string EWS_USERNAME = "user";
const string EWS_PASSWORD = "pass";
const string EWS_DOMAIN = "domain";
const string EWS_URL = "https://exchange-server/EWS/Exchange.asmx";

var ews = new ExchangeServiceBinding();
ews.Credentials = new NetworkCredential(EWS_USERNAME, EWS_PASSWORD, EWS_DOMAIN);
ews.Url = EWS_URL;

var email = new MessageType();
email.IsFromMe = false;
email.From = new SingleRecipientType();
email.From.Item = new EmailAddressType();
email.From.Item.EmailAddress = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="066074696b46637e676b766a632865696b" rel="noreferrer noopener nofollow">[email protected]</a>";

email.ToRecipients = new EmailAddressType[1] { new EmailAddressType { EmailAddress = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ae8fff9f3eaf3fff4eedaffe2fbf7eaf6ffb4f9f5f7" rel="noreferrer noopener nofollow">[email protected]</a>" } };

email.Subject = "Subject";

email.Body = new BodyType();
email.Body.BodyType1 = BodyTypeType.HTML;
email.Body.Value = "<strong>Test</strong>";

var emailToSave = new CreateItemType();
emailToSave.Items = new NonEmptyArrayOfAllItemsType();

emailToSave.Items.Items = new ItemType[1] { email };
emailToSave.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
emailToSave.MessageDispositionSpecified = true;

ews.CreateItemCompleted += new CreateItemCompletedEventHandler(ExchangeWebServices_CreateItemCompleted);

ews.CreateItemAsync(emailToSave, callbackState);

我的问题是如何发送包含 HTML 和纯文本正文的多部分电子邮件?

最佳答案

Exchange 自动生成您邮件的纯文本版本。您无需执行任何操作即可实现这一点。

关于c# - 如何使用 Exchange Web 服务发送包含 text/plain 和 text/html 的多部分电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7956527/

相关文章:

c# - X文档异常: Root element is missing

c# - 标准偏差计算在 C# 中不起作用?

c# - 与多个项目共享单元测试

exchange-server - Office365 autodiscover.xml 返回 403 Forbidden

exchange-server - 交换 : Is it possible to search for a custom Extended Property across all mailboxes?

soap - Exchange EWS 未返回日历的邮件正文

c# - "await Task.Run(); return;"和 "return Task.Run()"之间有什么区别吗?

c# - 当 Npgsql 连接池达到 Max 时会发生什么

exchangewebservices - 将 ActiveSync 邮箱 ID 转换为 EWS 文件夹 ID

c# - EWS 邮箱组流订阅