Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I add a custom header to a MailItem?

633 views
Skip to first unread message

Robert Nicholson

unread,
Feb 10, 2002, 6:51:56 AM2/10/02
to
Using VBA Macros what API allows me to add a X-Custom header to a mail item?
I have a VBA Macro that goes through my Sent Items folder and removes
certain attachments and I want to attach a note to the email message to
denote this. So I want to add something in the form of a X-Custom header to
annotate this. Is there a more appropriate way to do this?


Dan Haygood

unread,
Feb 11, 2002, 8:10:16 PM2/11/02
to
Robert -

I have been poking around with different varaitions on this question for a
few weeks, and nobody seems to know how to make this work. A couple of
notes, though....

One thing to remember are that X-headers are not part of Outlook or
Exchange. They are part of the SMTP transport that these programs can use
to deliver messages. Of course, they can deliver messages using other
transport mechanisms, also.

Microsoft surfaces SMTP transport headers in Outlook's U/I as "Internet
headers." I guess the fact that they could have come from any system using
SMTP, Internet or intranet, is a pretty minor simplification.

So, you need to be looking at things called "transport headers". You won't
find any in the Outlook Automation model. But you will find "message
properties" in CDO and MAPI. Look for identifiers like
PR_TRANSPORT_HEADERS.

The Redemption.dll often mentioned here will actually let you set these
properties through Outlook's automation foo, but a couple of other case
studies I saw on the Yahoo "Outlook Development" group (I forget its name),
said that the transport headers were getting stripped on the way out.

I wasn't able to tell whether Outlook/MAPI on the local machine was
stripping the headers, or if Exchange was the culprit. Exchange certainly
mangles them, to advertise Exchange as the mailer; and I certainly wouldn't
expect Exchange to honor RFC822 admonitions to maintain existing headers, so
even if Outlook is well-behaved, Exchange probably still hurts you.

I was so saddend by the accounts I read that I didn't even try setting the
properties, though, especially since, if it didn't work the first time, the
second step involved setting up a sniffer to see if it was Outlook or
Exchange stripping off my headers.

Another popular way to include outgoing X-headers involves an exploit
against the Subject line. "Subject" is a defined header, and headers can
concievably appear in any order (with certain rules). So, what if the line
under "Subject: My Nifty E-Mail" was "X-My-Header: Cool"? Well, then, you'd
have yourself a custom header!

So, what if your subject line was: "Subject: My Nifty E-Mail\nX-My-Header:
Cool"? Note the embedded newline, representing, on MS platforms, a CR/LF
pair. Well, when you spool that out, it looks just like the line after the
Subject is an X-header. So, the exploit is to set your mail item's .Subject
property:

item.Subject = _
"My Nifty E-Mail" & _
Chr(13) & Chr(10) & _
"X-My-Header: Cool"

Unfortunately, it didn't take much smarts for MS to figure out that subject
contents shouldn't contain CR/LF, or, someone could start putting in all the
x-headers they wanted...or, real headers, for that matter, if that someone
was a bad guy, and wanted to confuse the "received-by" chain on some spoofed
e-mail. On OL2002, at least on my machine, this exploit no longer works.

What MS actually does seems to vary. On Exch->Exch, MS seems to actually
try to preserve the CR/LF as a multi-line subject (But on my machine, that
doesn't come out looking right.). On Internet-routed mail, the CR/LF and
anything after it seems to disappear.

One last note: You may be tempted to try to use UserProperties. There are
some mumblings that UserProperties are preserved, even on transport across
the Internet, if you use RTF as your message format. Of course, that means
you will curse most of Internet recipients with useless WinMail.dat files,
and because your attachments get grumugled up in WinMail.dat, you won't be
able to send attachments clearly. That kind of restriction on using RTF for
property preservation didn't make sense for me, so I didn't bother exploring
it further.

So, I've given up for now on anything using customer headers or
UserProperties preservation. I am thinking I may just have to create a
plain text attachment to carry the extra information from place to place.

If your research and experience is any different, let me know. But so far,
no one has risen to an earlier challenge to send me an e-mail from
OL2002/E2000 with a custom header (dan at haygoods d0t 0rg).

Hope this helps, in some indirect way,
- Dan

"Robert Nicholson" <rob...@elastica.com> wrote in message
news:OcR1EnisBHA.2524@tkmsftngp04...

0 new messages