EWS 托管 WEB API 在单个调用中检索 HTML 和文本电子邮件
本文关键字:HTML 检索 文本 电子邮件 调用 WEB 托管 API 单个 EWS | 更新日期: 2023-09-27 18:32:51
我正在使用 EWS Web 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.HTML
或BodyType.Text
来检索电子邮件内容,但我需要一个调用来检索两种类型(文本和 HTML)。
如何在一次调用中检索 HTML 和文本正文?
假设您的目标是Exchange 2013+,我认为如果将ItemSchema.TextBody添加到属性集,则可以获取文本正文。