how to get sender's (ISP's) IP adress

G

Guy Lateur

Hi all,

I would like to know how I can retrieve the sender's IP adres (or rather,
the IP closest to the sender, as found in the Internet Headers in Message
Options) from a mail item using VB. I can't seem to find the right property
for this. Does anybody know how to do this?

TIA,
g
 
M

Michael Bauer

Hi,

the OOM doesn´t provide this info and CDO AFAIK also doesn´t. You could
use CDO, read the CdoPR_TRANSPORT_MESSAGE_HEADERS and search in that
string IP addresses.
 
G

Guy Lateur

Thanks a lot, Michael, it works!




Michael Bauer said:
Hi,

the OOM doesn´t provide this info and CDO AFAIK also doesn´t. You could
use CDO, read the CdoPR_TRANSPORT_MESSAGE_HEADERS and search in that
string IP addresses.
 
D

Dmitry Streblechenko

Note however that there is absolutely no requirement for the sender's IP
address to be present in the headers. And if it is there, it could've been
easily forged.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

Guy Lateur

Thanks for the info. I've indeed noticed that not all messages contain this
header info, but I thought that was because they were sent from within our
company LAN.

Anyway, does anybody know of a better way to check the (true) origin of
mail? We've been getting quite some spam/infected mail here, so I've been
putting up some rules in Outlook to block messages based on IP adress (I
knew the sender's email adress was fake). Of course, I'd like to check the
messages in the user's inbox to make sure I'm not blocking any genuine
messages.

Is there anything useful that can't be forged?
 
G

Guy Lateur

I have another related question. As Dmitry pointed out, not all messages
have this header information. Even worse, if a message doesn't contain the
info, my script generates a runtime error [MAPI_E_NOT_FOUND(8004010F)] on
the following line:
InternetHeaders = objFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Value

Does anyone know how I can avoid program termination if the headers are not
present? So basically, I'd like to check wether or not I can retrieve the
headers before actually doing it. Any ideas?

Cheers,
g
 
M

Michael Bauer

In this case, please check whether the requested Field object exists or
not, before you access its Value property.

In general, just add error handlers to your code.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook


Guy Lateur said:
I have another related question. As Dmitry pointed out, not all messages
have this header information. Even worse, if a message doesn't contain the
info, my script generates a runtime error [MAPI_E_NOT_FOUND(8004010F)] on
the following line:
InternetHeaders = objFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Value

Does anyone know how I can avoid program termination if the headers are not
present? So basically, I'd like to check wether or not I can retrieve the
headers before actually doing it. Any ideas?

Cheers,
g



Dmitry Streblechenko said:
Note however that there is absolutely no requirement for the sender's IP
address to be present in the headers. And if it is there, it could've been
easily forged.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
D

Dmitry Streblechenko

Nope. Unless your code runs on the server so that it can determine the IP
address of the incoming connection, there is no way to do that.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

guy lateur

Allright! That sounds good, because I indeed plan to implement this on the
server (win2k3 + exchange). That way my users are completely shielded from
this.

One thing, though: we're no longer talking about programming Outlook, then,
but Exchange, right? Is that comparable at all? I'm quite new to this all,
you see..

Thanks again for your input, guys, much appreciated!
 
G

guy lateur

I'll try that monday at work. I'm not really sure what you mean, though.
I've tried IsMissing() et al, but that didn't seem to work.

Is there a function Exists(object) or something? Or are we talking about
something like a try-catch thing?
 
D

Dmitry Streblechenko

I meant not just on the server, your *app* must be the SMTP server that will
be accepting messages from the sending server.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

guy lateur

Oh, I see.. Well, that's too bad, then, because I'm not planning on going
quite that deep with this.

It does beg the question, though, why Exchange (being the smpt server you're
refering to) doesn't allow me (the admin) to access this info. I mean, is
that in itself a security breach or something?
 
M

Michael Bauer

You could use something like this:

On Error Resume Next
Dim oField as Mapi.Field
Set oField=objFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS)
If oField is Nothing then
Err.Clear
' Field doesn´t exist
Else
InternetHeaders =
objFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Value
Endif

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook


guy lateur said:
I'll try that monday at work. I'm not really sure what you mean, though.
I've tried IsMissing() et al, but that didn't seem to work.

Is there a function Exists(object) or something? Or are we talking about
something like a try-catch thing?
 

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