Changing email message header

Add-in Express™ Support Service
That's what is more important than anything else

Changing email message header
 
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
I found some examples that retrieve the header of an email message (ADX Toys among them) I want to use those examples to now try to change the headers and save the item back in Outlook.

Before spending a lot of time doing this investigation I wanted to check if anyone here has done something similar before. Is there any general recommendations? Is this a valid approach at all?

My final goal is to “mark” some messages that match a certain criteria. For that, I thought I could change the message header information, which is normally out of the user’s reach (it doesn’t need to be private, so it’s not an issue that the user can see the message Options). Is there any other way to store a “hidden property” for each message that I can rely on it’s not going to be changed when messages are moved from one folder to another, etc?

I’ve read there are some issues with Exchanges messages not having the header available. Is there any way to get around this problem?

Thank you in advance for any hints..
Posted 28 Feb, 2006 13:39:37 Top
Sergey Grischenko


Add-in Express team


Posts: 7235
Joined: 2004-07-05
Hi Esteban.

I would advise you to use named properties to mark your mails.
Please read 'Named Properties' chapter in MSDN to learn more about it.
Posted 01 Mar, 2006 08:42:41 Top
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
Thank you Sergey, I found the documentation you referred me to and will give it a try.

Is anyone familiar with this approach? I seem to remember reading that the "named properties" may not be compatible with some email servers. Any hints?

Thanks in advance
Posted 01 Mar, 2006 10:14:22 Top
Sergey Grischenko


Add-in Express team


Posts: 7235
Joined: 2004-07-05
Esteban, I know it 100% works with Exchnage Server.
Posted 01 Mar, 2006 10:19:04 Top
Brad Smith




Posts: 49
Joined: 2005-11-22
When you talk about the "Header", do you mean the SMTP header? Indeed there is no SMTP header for messages constrained within an Exchange environment. Those headers are generated by Exchange when a message is about to be sent to the Internet. You don't have "direct" access from within an add-in (though there are some tricks).

For a message that's to be constrained within an Exchange environment (ie. within your corporation, then named properties or UserProperties are definitely the best way to go). They're stored in Exchange as part of the message. *But*, for the most part UserProperties and MAPI Named Properties don't survive transit via the internet.

So there's your first decision, internal messages only, or do you have to worry about internet transmission?

Brad.
Posted 04 Mar, 2006 10:45:50 Top
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
Thank you Brad for this valuable information. I'm not constrained within an Exchange environment (only), so I think it's safer to not relay on this technique.

I still need to mark the messages somehow. That's why I wanted to use the EntryID approach and make the connection to an external database. Just like Microsoft is doing it with their Elixir sample add-in (http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnbda/html/OtlkLOBCRM.asp)

However, they contrain the application to a specific folder, so they don't have to deal with cases where the EntryID possibly changing when the user moves messages from one folder to another one.

I will give it another try to changing the header information. By the way, I may not be using the appropriate language. What I mean with "header" is those fields that go with the email message that you can get when using "Options" for the message in Outlook. I was thinking on adding a new X-Header to the message with my own information. Do you think this is still a good idea in general?

Thanks again for the advice..
Posted 07 Mar, 2006 14:19:24 Top
Brad Smith




Posts: 49
Joined: 2005-11-22
Any mechanism *other* than an X-header will not survive any sort of internet transfer. Things like EntryID values, named or custom properties, etc cease to exist as soon at the message is relayed out an SMTP server. So the Elixir sample, for example, is useless as soon as the message goes out to the internet.

The headers of which you speak are indeed the SMTP (or Internet) headers. Adding an X-header from within Outlook requires use of an undocumented and unsupported hack. I can point you towards some sample VB and maybe C++ code that does this, but I can't tell you how it might be done in ADX (it uses a special MAPI Named Property). If you're willing to take that risk, it's feasible to add a property that can be recalled via MAPI for messages within your Exchange environment or via the SMTP headers for messages that went out on the internet.

Posted 08 Mar, 2006 10:20:28 Top
Esteban Astudillo




Posts: 146
Joined: 2006-02-27
I appreciate your hints Brad. You clarified for me a lot of concepts. Thanks a lot.
Posted 08 Mar, 2006 14:12:06 Top
Sergey Grischenko


Add-in Express team


Posts: 7235
Joined: 2004-07-05
Hi Brad.

Thank you very much for your help.
I am very interested in the examples (VB and C++) mentioned above.
Could you please provide them? I am sure I will manage to rewrite C++ code in C#.
Posted 08 Mar, 2006 16:53:45 Top
Brad Smith




Posts: 49
Joined: 2005-11-22
Sergey, I'll put together some code fragments and send them to you directly ASAP. You can then massage as you see fit and make it available (after testing, of course). :-)
Posted 09 Mar, 2006 08:35:19 Top