EWS托管WEB API在一次调用中检索HTML和文本电子邮件

时间:2014-12-01 15:44:23

标签: c# exchangewebservices ews-managed-api

我正在使用EWS网络API检索电子邮件,以下是我的代码

 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

    service.Credentials = new WebCredentials(EWSUserName, EWSPassword);

    service.TraceEnabled = true;
    service.TraceFlags = TraceFlags.All;

    service.AutodiscoverUrl(EWSUserName, RedirectionUrlValidationCallback);


    PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients, EmailMessageSchema.Sender,
                    EmailMessageSchema.ConversationId, EmailMessageSchema.Id);
    itempropertyset.RequestedBodyType = BodyType.HTML;
  FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(100),);
    ServiceResponseCollection<GetItemResponse> items =
                service.BindToItems(findResults.Select(item => item.Id), itempropertyset);


    MailItem[] mailItemsDetail = items.Select(item =>
    {
        return new MailItem()
        {
            From = ((Microsoft.Exchange.WebServices.Data.EmailAddress)item.Item[EmailMessageSchema.From]).Address,
            Recipients = ((Microsoft.Exchange.WebServices.Data.EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray(),
            Subject = item.Item.Subject,
            Body = item.Item.Body.ToString(),
            DateTimeSent = item.Item.DateTimeSent,
            EmailMessageID = item.Item.Id.UniqueId,
        };

    }).ToArray();

我必须使用BodyType.HTMLBodyType.Text来检索电子邮件内容,但我需要一次调用来检索这两种类型(文本和HTML)。

如何在一次通话中检索HTML和Text正文?

1 个答案:

答案 0 :(得分:0)

假设您的目标是Exchange 2013+,我认为如果您将ItemSchema.TextBody添加到属性集中,则可以获取文本正文。