Solved

Access all headers programmatically?

Posted on 2002-07-11
5
310 Views
Last Modified: 2008-02-26
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
0
Comment
Question by:jonawebb
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
Neo_mvps earned 200 total points
ID: 7147922
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.

Cheers,
/Neo

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.


0
 

Author Comment

by:jonawebb
ID: 7150108
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);
     ATLASSERT(pMail);
     IUnknown* pUnk = NULL;
     pMail->get_MAPIOBJECT(&pUnk);
     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_HEADERS;
     pMAPIProp->GetProps(&ar, PT_UNSPECIFIED, &nProps, &arProps);
0
 

Author Comment

by:jonawebb
ID: 7150125
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.
0
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 7150202
Very cool and thanks for the grade of A.
0
 
LVL 16

Expert Comment

by:Neo_mvps
ID: 7150206
oops... should have said B.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now