PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook Interoperability Getting headers of a MailItem?

Reply

Getting headers of a MailItem?

 
Thread Tools Rate Thread
Old 12-06-2006, 05:39 PM   #1
280Z28
Guest
 
Posts: n/a
Default Getting headers of a MailItem?


Using the new Office 12 SDK.

I'm trying to get the headers of a MailItem programmatically. Therse are the
same things you would see if you right click in Outlook and go to Message
Options.

I can get the body of the message easily, with the MailItem.Body property.
The place where I need the headers is in an event handler for the
Folder.Items.ItemAdd event. In particular, I'm trying to do something when
items are added to the folder and have certain SpamAssassin information in
the header:

X-Spam-Flag: YES
X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on
box36.bluehost.com
X-Spam-Level: *******************************
X-Spam-Status: Yes, score=31.5 required=5.0 tests=BAYES_95,
DATE_IN_FUTURE_96_XX,DATE_SPAMWARE_Y2K,FORGED_AOL_TAGS,
FORGED_MUA_AOL_FROM,FROM_ILLEGAL_CHARS,HEAD_ILLEGAL_CHARS,
HTML_MESSAGE,HTML_MIME_NO_HTML_TAG,MIME_BOUND_DD_DIGITS,
MIME_HTML_ONLY,MIME_HTML_ONLY_MULTI,MISSING_MIMEOLE,MSGID_SPAM_CAPS,
REPTO_QUOTE_AOL,SUBJ_ILLEGAL_CHARS,UNPARSEABLE_RELAY autolearn=no
version=3.1.0


  Reply With Quote
Old 12-06-2006, 06:29 PM   #2
Ken Slovak - [MVP - Outlook]
Guest
 
Posts: n/a
Default Re: Getting headers of a MailItem?

Assuming you have a mail item instantiated:

Dim oPropAccessor As Outlook.PropertyAccessor

Const PR_MAIL_HEADER_TAG = _
"http://schemas.microsoft.com/mapi/proptag/0x007D001E"

'only works if Application.IsTrusted is True
Set oPropAccessor = oItem.PropertyAccessor

strHeaders = oPropAccessor(PR_MAIL_HEADER_TAG)

From there the headers are in the string variable strHeaders and can be
parsed out.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"280Z28" <msnewsgroup@djss.net> wrote in message
news:O8GGF7jjGHA.1272@TK2MSFTNGP03.phx.gbl...
> Using the new Office 12 SDK.
>
> I'm trying to get the headers of a MailItem programmatically. Therse are
> the same things you would see if you right click in Outlook and go to
> Message Options.
>
> I can get the body of the message easily, with the MailItem.Body property.
> The place where I need the headers is in an event handler for the
> Folder.Items.ItemAdd event. In particular, I'm trying to do something when
> items are added to the folder and have certain SpamAssassin information in
> the header:
>
> X-Spam-Flag: YES
> X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on
> box36.bluehost.com
> X-Spam-Level: *******************************
> X-Spam-Status: Yes, score=31.5 required=5.0 tests=BAYES_95,
> DATE_IN_FUTURE_96_XX,DATE_SPAMWARE_Y2K,FORGED_AOL_TAGS,
> FORGED_MUA_AOL_FROM,FROM_ILLEGAL_CHARS,HEAD_ILLEGAL_CHARS,
> HTML_MESSAGE,HTML_MIME_NO_HTML_TAG,MIME_BOUND_DD_DIGITS,
> MIME_HTML_ONLY,MIME_HTML_ONLY_MULTI,MISSING_MIMEOLE,MSGID_SPAM_CAPS,
> REPTO_QUOTE_AOL,SUBJ_ILLEGAL_CHARS,UNPARSEABLE_RELAY autolearn=no
> version=3.1.0
>
>


  Reply With Quote
Old 12-06-2006, 06:36 PM   #3
Ken Slovak - [MVP - Outlook]
Guest
 
Posts: n/a
Default Re: Getting headers of a MailItem?

I left out a method that must be called on the PropertyAccessor object; the
code line should read as follows:

strHeaders = oPropAccessor.GetProperty(PR_MAIL_HEADER_TAG)

Sorry about that.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Ken Slovak - [MVP - Outlook]" <kenslovak@mvps.org> wrote in message
news:O8ogAXkjGHA.456@TK2MSFTNGP05.phx.gbl...
> Assuming you have a mail item instantiated:
>
> Dim oPropAccessor As Outlook.PropertyAccessor
>
> Const PR_MAIL_HEADER_TAG = _
> "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
>
> 'only works if Application.IsTrusted is True
> Set oPropAccessor = oItem.PropertyAccessor
>
> strHeaders = oPropAccessor(PR_MAIL_HEADER_TAG)
>
> From there the headers are in the string variable strHeaders and can be
> parsed out.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm


  Reply With Quote
Old 12-06-2006, 07:04 PM   #4
=?Utf-8?B?MjgwWjI4?=
Guest
 
Posts: n/a
Default Re: Getting headers of a MailItem?

Thank you. I got it working. I'm using this to automatically mark certain
messages that go into the junk folder as read so I don't have to review them.

const string PR_MAIL_HEADER_TAG =
"http://schemas.microsoft.com/mapi/proptag/0x007D001E";
Outlook.PropertyAccessor oPropAccessor = mailItem.PropertyAccessor;
string headers = (string)oPropAccessor.GetProperty( PR_MAIL_HEADER_TAG );
bool spam = headers.Contains( "X-Spam-Flag: YES" );

"Ken Slovak - [MVP - Outlook]" wrote:

> Assuming you have a mail item instantiated:
>
> Dim oPropAccessor As Outlook.PropertyAccessor
>
> Const PR_MAIL_HEADER_TAG = _
> "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
>
> 'only works if Application.IsTrusted is True
> Set oPropAccessor = oItem.PropertyAccessor
>
> strHeaders = oPropAccessor(PR_MAIL_HEADER_TAG)
>
> From there the headers are in the string variable strHeaders and can be
> parsed out.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "280Z28" <msnewsgroup@djss.net> wrote in message
> news:O8GGF7jjGHA.1272@TK2MSFTNGP03.phx.gbl...
> > Using the new Office 12 SDK.
> >
> > I'm trying to get the headers of a MailItem programmatically. Therse are
> > the same things you would see if you right click in Outlook and go to
> > Message Options.
> >
> > I can get the body of the message easily, with the MailItem.Body property.
> > The place where I need the headers is in an event handler for the
> > Folder.Items.ItemAdd event. In particular, I'm trying to do something when
> > items are added to the folder and have certain SpamAssassin information in
> > the header:
> >
> > X-Spam-Flag: YES
> > X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on
> > box36.bluehost.com
> > X-Spam-Level: *******************************
> > X-Spam-Status: Yes, score=31.5 required=5.0 tests=BAYES_95,
> > DATE_IN_FUTURE_96_XX,DATE_SPAMWARE_Y2K,FORGED_AOL_TAGS,
> > FORGED_MUA_AOL_FROM,FROM_ILLEGAL_CHARS,HEAD_ILLEGAL_CHARS,
> > HTML_MESSAGE,HTML_MIME_NO_HTML_TAG,MIME_BOUND_DD_DIGITS,
> > MIME_HTML_ONLY,MIME_HTML_ONLY_MULTI,MISSING_MIMEOLE,MSGID_SPAM_CAPS,
> > REPTO_QUOTE_AOL,SUBJ_ILLEGAL_CHARS,UNPARSEABLE_RELAY autolearn=no
> > version=3.1.0
> >
> >

>
>

  Reply With Quote
Old 13-06-2006, 10:08 PM   #5
280Z28
Guest
 
Posts: n/a
Default Re: Getting headers of a MailItem?

I suggest adding this to the new SDK as a property:

MailItem.Headers { get; }

"Ken Slovak - [MVP - Outlook]" <kenslovak@mvps.org> wrote in message
news:O8ogAXkjGHA.456@TK2MSFTNGP05.phx.gbl...
> Assuming you have a mail item instantiated:
>
> Dim oPropAccessor As Outlook.PropertyAccessor
>
> Const PR_MAIL_HEADER_TAG = _
> "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
>
> 'only works if Application.IsTrusted is True
> Set oPropAccessor = oItem.PropertyAccessor
>
> strHeaders = oPropAccessor(PR_MAIL_HEADER_TAG)
>
> From there the headers are in the string variable strHeaders and can be
> parsed out.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "280Z28" <msnewsgroup@djss.net> wrote in message
> news:O8GGF7jjGHA.1272@TK2MSFTNGP03.phx.gbl...
>> Using the new Office 12 SDK.
>>
>> I'm trying to get the headers of a MailItem programmatically. Therse are
>> the same things you would see if you right click in Outlook and go to
>> Message Options.
>>
>> I can get the body of the message easily, with the MailItem.Body
>> property. The place where I need the headers is in an event handler for
>> the Folder.Items.ItemAdd event. In particular, I'm trying to do something
>> when items are added to the folder and have certain SpamAssassin
>> information in the header:
>>
>> X-Spam-Flag: YES
>> X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on
>> box36.bluehost.com
>> X-Spam-Level: *******************************
>> X-Spam-Status: Yes, score=31.5 required=5.0 tests=BAYES_95,
>> DATE_IN_FUTURE_96_XX,DATE_SPAMWARE_Y2K,FORGED_AOL_TAGS,
>> FORGED_MUA_AOL_FROM,FROM_ILLEGAL_CHARS,HEAD_ILLEGAL_CHARS,
>> HTML_MESSAGE,HTML_MIME_NO_HTML_TAG,MIME_BOUND_DD_DIGITS,
>> MIME_HTML_ONLY,MIME_HTML_ONLY_MULTI,MISSING_MIMEOLE,MSGID_SPAM_CAPS,
>> REPTO_QUOTE_AOL,SUBJ_ILLEGAL_CHARS,UNPARSEABLE_RELAY autolearn=no
>> version=3.1.0
>>
>>

>



  Reply With Quote
Old 14-06-2006, 02:32 PM   #6
Ken Slovak - [MVP - Outlook]
Guest
 
Posts: n/a
Default Re: Getting headers of a MailItem?

Don't wait for it to happen. You now have access to that property and any
others through the PropertyAccessor, just use that.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"280Z28" <msnewsgroup@djss.net> wrote in message
news:eSOmQ2yjGHA.3304@TK2MSFTNGP03.phx.gbl...
>I suggest adding this to the new SDK as a property:
>
> MailItem.Headers { get; }


  Reply With Quote
Old 14-06-2006, 05:42 PM   #7
280Z28
Guest
 
Posts: n/a
Default Re: Getting headers of a MailItem?

That's what I'm doing. You can see how I'm using this in my solution to the
problem named in this topic in Outlook General:

Outlook should let me prioritize rules to run before junk filters

I believe my solution could also be done by anyone through Outlook macros in
VB, but it's easier for me to create an add-in since I have VS2005 and know
C# but not VB.

Sam

"Ken Slovak - [MVP - Outlook]" <kenslovak@mvps.org> wrote in message
news:OljJBc7jGHA.1264@TK2MSFTNGP05.phx.gbl...
> Don't wait for it to happen. You now have access to that property and any
> others through the PropertyAccessor, just use that.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
> http://www.slovaktech.com/products.htm
>
>
> "280Z28" <msnewsgroup@djss.net> wrote in message
> news:eSOmQ2yjGHA.3304@TK2MSFTNGP03.phx.gbl...
>>I suggest adding this to the new SDK as a property:
>>
>> MailItem.Headers { get; }

>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off