Chase Ernst
Chase Ernst

Reputation: 1155

No body in outlook email

I am trying to get the body and head of an email upon receiving it in outlook. I am using the NewMailEx event handler to manage all emails that are coming in.

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)

Dim olApp As Outlook.Application
Dim oNS         As NameSpace
Dim oFolder     As MAPIFolder
Dim oNewMail    As MailItem
Set olApp = Outlook.Application
Set oNS = GetNamespace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderInbox)
Set oNewMail = oFolder.Items.GetFirst

Set Msg = oNS.GetItemFromID(EntryIDCollection)
MsgBox Msg.Body

End Sub

This function is being called successfully, and I can get the header of the email by using:

MsgBox Msg

But when I try to use Msg.Body nothing is displayed in the MsgBox. Additionally, when I use Msg.HTMLBody I can see the html in the MsgBox, but still there is nothing in the tag.

Any suggestions on what I am doing wrong here?

Upvotes: 0

Views: 319

Answers (1)

Chase Ernst
Chase Ernst

Reputation: 1155

I ended up figuring this out myself.

Because the email that I am working with is IMAP, only the subject line is downloaded from the server until the email is clicked, then downloading the body.

I was able to access the body of the email by first accessing the subject line beforehande like so:

Set Msg = oNS.GetItemFromID(EntryIDCollection)
MsgBox Msg
MsgBox Msg.Body

Upvotes: 2

Related Questions