Outlook VBA中的.Body无法获取纯文本电子邮件的文本

时间:2018-12-23 00:49:49

标签: vba outlook outlook-vba

。Mailitem的主体未返回任何内容

我正在使用entryID来访问入站电子邮件,并使用Application.Session.GetItemFromID设置对象

strID = olitem.EntryID
Set olitem = Application.Session.GetItemFromID(strID)

一旦我设置了olitem
    Set olitem = Application.Session.GetItemFromID(strID) 它显示电子邮件已被访问,但是当sText = olitem.Body运行时,stext最终为空。

这是从Outlook规则触发的整个代码。 This shows watch window with .body empty

Sub ParseEPDMRequest(olitem As Outlook.MailItem)


Dim arr() As String
Dim ECONum As String
Dim ReqID As String

Dim sText As String
Dim strID As String

strID = olitem.EntryID
Set olitem = Application.Session.GetItemFromID(strID)

sText = olitem.Body
arr = Split(olitem.Body, ":")
arr = Split(arr(15), " ")
ECONum = GetECONum(arr(8))
sText = olitem.Subject
ReqID = GetReqId(sText)

Call TEAMtoEPDMPush(ECONum & ".xml", ReqID)

End Sub

1 个答案:

答案 0 :(得分:0)

在某些情况下,该邮件可以没有纯文本正文。您必须检查正文的格式(see BodyFormat property):

strID = olitem.EntryID
Set olitem = Application.Session.GetItemFromID(strID)
If olitem.BodyFormat=OlBodyFormat.olFormatPlain Then
   sText = olitem.Body
   ...
ElseIf  olitem.BodyFormat=OlBodyFormat.olFormatHTML Then 
   ...