Message headers

L

Leon Mayne

Hi all,
I'm trying to get the message headers and body from an email. I am able to
get the message body using:

Set oOL = CreateObject("Outlook.Application")
For x = 1 To oOL.ActiveExplorer.Selection.Count
msgBody = oOL.ActiveExplorer.Selection.Item(x).Body
Next

Which works fine, but I can't seem to find a way to get the headers in the
same fashion (from within the loop above).

Can anyone help?
 
L

Leon Mayne

Leon Mayne said:
Hi all,
I'm trying to get the message headers and body from an email.

OK, I've managed to find out how to do this now, but can anyone tell me how
to find out what format an email is in (Plain text / HTML)? I am writing the
code using ActiveExplorer.Selection.Item(x) so I can't use e.g:
If (oInspector.EditorType = olEditorHTML) Then
 
S

Sue Mosher [MVP]

EditorType is indeed the correct approach. You can use the MailItem.GetInspector method to return an Inspector.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
L

Leon Mayne

EditorType is indeed the correct approach. You can use the
MailItem.GetInspector method to return an Inspector.

But I thought you needed to have the message opened to use an inspector? I
want to do it from the message list (explorer)
 
S

Sue Mosher [MVP]

No. GetInspector returns an undisplayed Inspector object if you use it on an item that is not open.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
L

Leon Mayne

Sue Mosher said:
No. GetInspector returns an undisplayed Inspector object if you use it on
an item that is not open.

It's OK, I've solved my own problem again!!
I retrieved the message body as HTML and then looped through to see if I
could find Outlook's 'Converted from plain text' message:

msgBody = oOL.ActiveExplorer.Selection.Item(x).HTMLBody
msgLines = Split(msgBody, vbCrLf)
For Each msgLine In msgLines
If Replace(msgLine, "<!-- Converted from text/plain format -->",
"") _
<> msgLine Then
' Message has been converted, so we change it back to
Plain text
msgBody = oOL.ActiveExplorer.Selection.Item(x).Body
Exit For
End If
Next

Yes I know it's very untidy code, but hey, it works!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

StoreID 2
MoveTo 7
Processing a list of emails 7
Add Hyperlink in Email 4
Sending message with multiple SMTP BCCs 2
E-mail Headers 2
Extract text from the message body and show in msgbox 1
Outlook.Send 4

Top