How can I send a multi-part email with text/plain and text/html with Exchange Web Services?

纵然是瞬间 提交于 2019-12-11 04:01:27

问题


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);

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


回答1:


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



来源:https://stackoverflow.com/questions/7956527/how-can-i-send-a-multi-part-email-with-text-plain-and-text-html-with-exchange-we

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!