Message headers

  • Thread starter Thread starter Leon Mayne
  • Start date Start date
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?
 
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
 
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
 
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)
 
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
 
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!
 
Back
Top