jonawebb
asked on
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
Jon Webb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
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::_MailIt
ATLASSERT(pMail);
IUnknown* pUnk = NULL;
pMail->get_MAPIOBJECT(&pUn
ATLASSERT(pUnk);
CComQIPtr<IMAPIProp, &IID_IMAPIProp> pMAPIProp(pUnk);
ATLASSERT(pMAPIProp);
SPropTagArray ar = {0};
ULONG nProps = 0;
SPropValue *arProps = NULL;
char *szResult = NULL;
ar.cValues = 1;
ar.aulPropTag[0] = PR_TRANSPORT_MESSAGE_HEADE
pMAPIProp->GetProps(&ar, PT_UNSPECIFIED, &nProps, &arProps);