Solved

Access all headers programmatically?

Posted on 2002-07-11
5
320 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
outlook email issue . 1 61
Outlook header - Return Path different to From address 2 56
MS Exchange 2016 license 5 34
max value in vbscript 7 10
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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: …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

734 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