我有一个VB.Net Visual应用程序。通过,我能够读取电子邮件并获得其主题和来源。我很难找到一种方法来阅读它的身体。我发现了四种不同的方法,但它们都给了我相同的结果,即文本如下:
<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看上去像是给了我电子邮件的html。我怎样才能在邮件正文中得到文本呢?那密码是什么?这是我尝试过的四种方法的代码:
Dim iv As ItemView = New ItemView(999)
iv.Traversal = ItemTraversal.Shallow
Dim inboxItems As FindItemsResults(Of Item) = Nothing
inboxItems = exch.FindItems(WellKnownFolderName.Inbox, iv)
Dim Count As Integer = inboxItems.Count
For Each i As Item In inboxItems
Dim Subject = i.Subject
Dim oMail As EmailMessage = EmailMessage.Bind(exch, i.Id)
Dim email = oMail.From.Address.ToString
'FIRST WAY TRIED
Dim body = i.Body.Text
'SECOND WAY TRIED
i.Load()
Dim bodyagain = i.Body
'THIRD WAY TRIED
Dim item As Item = Item.Bind(exch, i.Id)
Dim bodynew = item.Body.ToString
'FOURTH WAY TRIED
For Each msg As EmailMessage In inboxItems
msg.Load()
Dim bodyTry = msg.Body
Next
Next发布于 2020-09-22 00:20:31
默认情况下,EWS将返回HTML主体,这就是为什么您总是得到该结果的原因。如果要使用文本正文,则需要使用属性集并指定该属性,然后在使用load或bind时加载该属性。
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来提高它的效率,因为这个代码循环对于大量的项执行起来会非常糟糕。
https://stackoverflow.com/questions/63997859
复制相似问题