Larry G. Wapnitsky
Larry G. Wapnitsky

Reputation: 1246

(Outlook 2010) Getting mail headers in C#

I've adapted Ken Slovak's code from here to read MailItem headers on a message before it is sent, but my header string is coming up as empty. Does this only work on received messages? If so, what would be a good method for pulling in the headers of the original message before composing Forward/Reply/Reply-To-All?

Here is my re-done code:

        Outlook.PropertyAccessor oPA = msg.PropertyAccessor as Outlook.PropertyAccessor;
        const string PR_MAIL_HEADER_TAG = @"http://schemas.microsoft.com/mapi/proptag/0x007D001E";
        try
        {
            string strHeaders = (string)oPA.GetProperty(PR_MAIL_HEADER_TAG);
        }
        catch { }

Thanks

Upvotes: 2

Views: 3306

Answers (1)

Niall Gray
Niall Gray

Reputation: 413

The message headers will only be populated once the original message has been sent. I tried your code and it returned the message headers for mail that I had received. I did get the security popup when trying to access the message though.

Upvotes: 1

Related Questions