Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access all headers programmatically?

Posted on 2002-07-11
5
Medium Priority
?
333 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 600 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Read this checklist to learn more about the 15 things you should never include in an email signature.
Mailbox Overload?
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
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: …

721 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