PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook Interoperability
Getting headers of a MailItem?
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook Interoperability
Getting headers of a MailItem?
![]() |
Getting headers of a MailItem? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 > > > > > > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
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 >> >> > |
|
|
|
#6 |
|
Guest
Posts: n/a
|
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; } |
|
|
|
#7 |
|
Guest
Posts: n/a
|
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; } > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

