Text EWS正文纯文本

Text EWS正文纯文本,text,exchange-server,exchangewebservices,Text,Exchange Server,Exchangewebservices,我使用EWS获取交换电子邮件,但是没有html,如何从电子邮件正文中获取纯文本? 现在我用这个: EmailMessage item = (EmailMessage)outbox.Items[i]; item.Load(); item.Body.Text 在项目的PropertySet中,需要将RequestedBodyType设置为BodyType.Text。下面是一个例子: PropertySet itempropertyset = new PropertySet(BaseProperty

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

EmailMessage item = (EmailMessage)outbox.Items[i];
item.Load();
item.Body.Text

在项目的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);
PropertySet itempropertyset=newpropertyset(BasePropertySet.FirstClassProperties);
itempropertyset.RequestedBodyType=BodyType.Text;
ItemView ItemView=新的ItemView(1000);
itemview.PropertySet=itempropertyset;
FindItemsResults findResults=service.FindItems(WellKnownFolderName.Inbox,“主题:TODO”,itemview);
Item=findResults.FirstOrDefault();
item.Load(itempropertyset);
控制台写入线(项目主体);
您可以使用

service.LoadPropertiesForItems(findResults, itempropertyset);
要加载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()

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

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

最短的方法如下:

item.Load(new PropertySet(BasePropertySet.IdOnly, ItemSchema.TextBody, EmailMessageSchema.Body));

这样做的好处是您可以同时获得文本正文和html正文。

请注意,属性集必须同时用于service.FindItems()和item.Load()为了使其正常工作,我在执行此操作时遇到此异常Microsoft.Exchange.WebServices.Data.ServiceObjectPropertyException:必须先加载或分配此属性,然后才能读取其属性value@JNM仅供参考。通过Aurinko.io REST API,使用Exchange服务器比使用EWS更方便。文档中的示例,或者如果您知道项目唯一id:
PropertySet plainTextPropertySet=newpropertyset(BasePropertySet.FirstClassProperties){RequestedBodyType=BodyType.Text,};EmailMessage=EmailMessage.Bind(服务、唯一标识、明文属性集);字符串body=emailMessage.body.Text在这种情况下,
$event
是什么<代码>$itmId
??-我有一封电子邮件,我使用的代码与你最后4行代码完全相同,但它仍然返回HTML而不是纯文本。如果我弄明白了,我会尽量记得回来的…:-/如果其他人好奇,只需使用EWS服务对象代替$event即可。