【问题标题】:How can I send a multi-part email with text/plain and text/html with Exchange Web Services?如何使用 Exchange Web 服务发送包含 text/plain 和 text/html 的多部分电子邮件?
【发布时间】:2011-10-31 16:23:53
【问题描述】:

我通过命令行使用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 = "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 和纯文本正文的多部分电子邮件?

【问题讨论】:

    标签: c# exchangewebservices


    【解决方案1】:

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

    【讨论】:

    • 你知道这方面的任何文件吗?我在这方面找不到任何东西。只是好奇。感谢您的帮助。
    • 谢谢。我想我只是不习惯这个,因为我通常通过 SMTP 发送。
    猜你喜欢
    • 2011-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-20
    • 2011-04-18
    • 1970-01-01
    • 2017-03-05
    相关资源
    最近更新 更多