EWS正文纯文本

JNM*_*JNM 28 text exchange-server exchangewebservices

我使用EWS来获取交换电子邮件,但是如何从电子邮件正文中获取纯文本,而不使用HTML?
现在我用这个:

EmailMessage item = (EmailMessage)outbox.Items[i];
item.Load();
item.Body.Text
Run Code Online (Sandbox Code Playgroud)

Eli*_*gne 65

在项目的PropertySet中,您需要将RequestedBodyType设置为BodyType.Text.这是一个例子:

PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties);
itempropertyset.RequestedBodyType = BodyType.Text;
ItemView itemview = new ItemView(1000);
itemview.PropertySet = itempropertyset;

FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, "subject:TODO", itemview);
Item item = findResults.FirstOrDefault();
item.Load(itempropertyset);
Console.WriteLine(item.Body);
Run Code Online (Sandbox Code Playgroud)

  • 请注意,PropertySet必须同时用于service.FindItems()和item.Load()才能使其正常工作. (7认同)

小智 7

在powershell中:

    .........    
$message = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($event.MessageData,$itmId)

$PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$PropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text
$message.Load($PropertySet)
$bodyText= $message.Body.toString()
Run Code Online (Sandbox Code Playgroud)


小智 7

我遇到过同样的问题。您所要做的就是设置您正在使用的属性集的RequestedBodyType属性。

    PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.Body);
    propSet.RequestedBodyType = BodyType.Text;
    var email = EmailMessage.Bind(service, item.Id, propSet);
Run Code Online (Sandbox Code Playgroud)


小智 5

最短的方法是这样的:

item.Load(new PropertySet(BasePropertySet.IdOnly, ItemSchema.TextBody, EmailMessageSchema.Body));
Run Code Online (Sandbox Code Playgroud)

这样做的好处是您可以同时获得 text-body 和 html-body。