VB.Net-无法获取电子邮件主体-交换服务

VB.Net-无法获取电子邮件主体-交换服务,vb.net,outlook,exchangewebservices,Vb.net,Outlook,Exchangewebservices,我有一个VB.NETVisualStudio应用程序。使用ExchangeWeb服务,我可以阅读电子邮件并从中获取其主题和内容。我很难找到阅读它身体的方法。我找到了四种不同的方法,但它们都给出了相同的结果,即文本如下: <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:sch

我有一个VB.NETVisualStudio应用程序。使用ExchangeWeb服务,我可以阅读电子邮件并从中获取其主题和内容。我很难找到阅读它身体的方法。我找到了四种不同的方法,但它们都给出了相同的结果,即文本如下:

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

........ MORE HTML

默认情况下,EWS将返回HTML正文,这就是您总是得到该结果的原因。如果您想要文本体,则需要使用属性集并指定该属性,然后在使用load或bind eg时加载该属性

 Dim bodyPropSet As New PropertySet(BasePropertySet.FirstClassProperties)
 bodyPropSet.Add(ItemSchema.Body)
 bodyPropSet.RequestedBodyType.Value = BodyType.Text
 i.Load(bodyPropSet)
 Dim bodyText = i.Body.Text
如果您经常这样做,那么可以考虑使用LoadPropertiesForItems来提高效率,因为代码循环在处理大量项目时会执行得非常糟糕

 Dim bodyPropSet As New PropertySet(BasePropertySet.FirstClassProperties)
 bodyPropSet.Add(ItemSchema.Body)
 bodyPropSet.RequestedBodyType.Value = BodyType.Text
 i.Load(bodyPropSet)
 Dim bodyText = i.Body.Text