0

.Body of Mailitem is not returning anything

I am using the entryID to get access to the inbound email and set the object using Application.Session.GetItemFromID

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

Once I set olitem
Set olitem = Application.Session.GetItemFromID(strID) it shows the email has been accessed, but when sText = olitem.Body is run stext ends up empty.

Here is the entire code that is fired from an Outlook Rule. 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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
CodeWriter
  • 71
  • 1
  • 13

1 Answers1

0

Under certain circumstances the message can have no plain text body. You have to check the format of the body (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 
   ...
Victor Ivanidze
  • 397
  • 2
  • 7
  • Thank you, I wll look into that. However, this is going to be used in a special case mail address that is being sent email from a known and configured system in which the emails format is controlled. That system is configured to deliver plain text as of now. I can configure it in multiple ways. rtf, html, attached csv, etc. This is why I am perplexed that .Body is empty. – CodeWriter Dec 23 '18 at 12:51
  • I have not tried this link solution but its likely going to solve the issue. https://stackoverflow.com/questions/42348518/vba-outlook-2010-received-mail-body-is-empty – CodeWriter Dec 23 '18 at 19:14
  • You have to be sure the plain text body is really exists -try to install OutlookSpy tool and play a bit with VB script there. – Victor Ivanidze Dec 24 '18 at 09:17
  • All 3 body flavors (plain text, HTLM, RTF) are automatically synchronized by the parent message store when the item is saved, so it is virtually impossible to have no plain text body while HTML or RTF are available. Are you sure you don;'t have a header-only item with the message body that has not been downloaded yet? – Dmitry Streblechenko Dec 25 '18 at 04:16