Access all headers programmatically?

Can anyone tell me if there is a way to get all the headers of an outlook message from a COM plugin? I have gotten access to the _MailItem, and can get headers like To:, Subject:, etc. using get_To, get_Subject, etc. But the _MailItem interface doesn't seem to allow me to get, for example, Return-Path. Is there a way I can get access to the "raw" headers, or to any headers that Outlook didn't know what to do with?

Jon Webb
Who is Participating?
Hi Jon,

The header information is not (directly) exposed in the Outlook Object Model.  Since it looks like you are developing in C/C+ and my experience is in VB, forgive me for the tip I'm going to give if the terminology isn't right.

The MailItem exposes a hidden property named MAPIOBJECT.  This property returns an IUnknown interface.  You would have to query this interface to get the Extended MAPI interface (IMessage?) to the object and then read transport header property.


PS - And for those using VB.  I would get the Entry ID/Stored ID and acquire the message via Collaboration Data Objects 1.21 and then read the field PR_TRANSPORT_MESSAGE_HEADERS.

PS - Jon, there is a really good MAPI forum list at peach ease lsoft where this quesiton could be answered from the C/C++ perspective.

jonawebbAuthor Commented:
Your answer, while not quite right, was invaluable in pointing me in the right direction. I'd be happy to give you full credit for the answer if you'll post it as such.

The solution I came up with was this:

#include <mapix.h>
#include <initguid.h>
#include <mapiguid.h>

     IDispatch *pItem;
        // ... initialize pItem by lookup in an Outlook folder

     CComQIPtr<Outlook::_MailItem> pMail(pItem);
     IUnknown* pUnk = NULL;
     CComQIPtr<IMAPIProp, &IID_IMAPIProp> pMAPIProp(pUnk);
     SPropTagArray ar = {0};
     ULONG nProps = 0;
     SPropValue *arProps = NULL;
     char *szResult = NULL;

     ar.cValues = 1;
     pMAPIProp->GetProps(&ar, PT_UNSPECIFIED, &nProps, &arProps);
jonawebbAuthor Commented:
I forgot to add:
1) The IDispatch returned by get_MAPIOBJECT supports two interfaces that I could find documentation on: IMAPIProp and IMAPISession. The fact that these interfaces are supported is undocumented anywhere; I found them by stepping through the assembly.
2) IMAPIProp is what you use to get the headers. In my code, GetProps returns the header as a string in the arProps parameter.
3) There are two different kinds of IMessage interfaces. The Microsoft documentation is even more elliptical and unorganized than usual.
Very cool and thanks for the grade of A.
oops... should have said B.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.