vbaoutlookemail-attachmentsoutlook-2007email-headers

Outllook VBA: Get Header Info from attached Email to an Email


Challenge description

I'd like to extract the header information from emails in an Outlook folder. This works so far. But there are Emails which where scanned by Spamassassin and found as being SPAM. So the SPAM Mail is attached to a new mail as Mail-Attachment.

Now i'd like to extract the header information from the original email-header.

What I already have I am getting the header information from the 'normal'- mail and can access the Outlook-mail-item and also found the attachement.

What I look for The easiest way to get the attachment as Outlook-mail-item so that I can perform the getHeader-operation operation. And, if possible without the need to open the attached mail.

Is there a way from the olmailItem to the attached mail (.msg-file) without opeining the attachment?

(Manually - with opening the mail - this can be done by opening the attached mail and look at the message options.)


Solution

  • Outlook does not let you directly access embedded message attachments. The best you can do is call Attachment.SaveAsFile to save the embedded message attachment as an MSG file, then open it using Application.Session.OpenSharedItem.

    If you using Redemption is an option (I am its author), it exposes EmbeddedMsg property on both the Attachment object (returned by the SafeMailItem object) and RDOAttachment object (returned by the RDOMail object).