如何使用Exchange Web Services发送包含文本/纯文本和文本/html的多部分电子邮件? [英] How can I send a multi-part email with text/plain and text/html with Exchange Web Services?

查看:274
本文介绍了如何使用Exchange Web Services发送包含文本/纯文本和文本/html的多部分电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I generated a namespace with the wsdl tool via the command line by pointing it to https://exchange-server/EWS/Services.wsdl.

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

I'm able to successfully send emails, using the code below:

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 = "from@example.com";

email.ToRecipients = new EmailAddressType[1] { new EmailAddressType { EmailAddress = "recipient@example.com" } };

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和纯文本正文的多部分电子邮件?

My question is how do I send a multi-part email that contains both an HTML and plain text body?

推荐答案

Exchange会自动生成邮件的纯文本版本.您无需为此做任何事情.

Exchange generates the plain text version of you mail automatically. You don't have to do anything for that to happen.

这篇关于如何使用Exchange Web Services发送包含文本/纯文本和文本/html的多部分电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆