How do I expose internet headers in code?

W

Wayne (CDX)

I haven't started this project, but I noticed that retrieving the Internet
Headers from a message doesn't seem to be built in.

I want to write a snippet of code to
1. Open a message from a "Spam" folder
2. Open the Internet Headers
3. Copy contents
4. Insert into a new message
5. Attach original message
6. Copy the IP of the sending mail server from the Internet headers
7. Open a URL using the copied IP.

All this is to automate Spam reporting to the offending ISP abuse address.
Obviously, getting at the Internet Headers is integral to making it work.

Any help would be greatly appreciated!
 
K

Ken Slovak - [MVP - Outlook]

You don't mention your Outlook version, but the code at the following link
shows how to get the Internet headers from a message using the CDO 1.21
library: http://www.slovaktech.com/code_samples.htm#InternetHeaders

You can't get the headers just using the Outlook object model except for
Outlook 2007, so with earlier versions you have to use CDO or a 3rd party
library such as Redemption (www.dimastr.com/redemption).

You do realize of course that many of the spams that are floating around use
forged IP addresses and domains so what you are attempting will in many
cases report as a spammer some poor innocent who's email address or domain
has been forged.
 
W

Wayne (CDX)

Sorry for that. I am currently running Outlook 2007, but I was interested in
both.

Thanks for the tips. Will let you know how it goes.

~Wayne
 
W

Wayne (CDX)

Oh - and I disagree about what I am doing to avoid spam. I have been quite
successful at blocking the majority of spam from my exchange server by
blocking the sender's mail server IP and reporting the abuse to the NOC of
the ISP. Most of the SPAM servers are bots running on some poor unsuspecting
user's computer. I never reply to the domain the email lists as where it came
from. Instead I enter the IP of the server that my server received it from
into www.dnsstuff.com and perform a whois to see the abuse email address. If
one is listed, I forward the message with the header in the body of my
message. So far I have had good success, reducing SPAM messages by about 80%.
If no abuse is listed, I block the IP (or network range, depending on the
source country and their fraud rating.) If I get a message from an IP a
second time that has been reported, it automatically getss blocked.

Of course, most people don't have their own exchange server, but I felt
reporting the abuse not only stops it from reaching me, it helps the Internet
community as a whole if the ISP takes appropriate action.

Anyway, thanks very much for your post.
 
M

MrVulcan

Hi Ken,

I'm using Outlook 2007 and I'm trying to create a macro to send the complete
source code of an e-mail off to SpamCop. If I understand you correctly, then
you're saying that the Outlook object model should suffice, to get the
headers of the selected e-mail.

Could you please explain how to get the complete headers of the selected
e-mail in Outlook 2007 using VBA?

Thanks in advance.

Kind regards,

Bert
 
K

Ken Slovak - [MVP - Outlook]

For Outlook 2007 you can use the new PropertyAccessor object.

So if you have an instance of a selected MailItem as oMail the following
would get the Internet headers:

' the following is a DASL property tag string, not a Web URL.
Const PR_TRANSPORT_MESSAGE_HEADERS = _
"http://schemas.microsoft.com/mapi/proptag/0x007D001E"

Dim headers As String
Dim oPropAccessor As Outlook.PropertyAccessor

Set oPropAccessor = oMail.PropertyAccessor
headers = oPropertyAccessor.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS)
 
M

MrVulcan

Hi Ken,

If I run the code you suggest, I get "Object required" at the following line:

Set oPropAccessor = oMail.PropertyAccessor

What's wrong?

I had a message earlier...something about the host application not running
macros? :s I managed to resolve that, but now I'm left with the error message
above. Could you please help me out?

Thanks in advance.

Kind regards,

Bert V.
 
K

Ken Slovak - [MVP - Outlook]

"if you have an instance of a selected MailItem as oMail"

You need to have an oMail object instantiated for this to work.
 
M

MrVulcan

Silly me! Sorry about that! :$

Ken Slovak - said:
"if you have an instance of a selected MailItem as oMail"

You need to have an oMail object instantiated for this to work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top