Determine OL sender w/o opening message?

  • Thread starter Thread starter Wild Bill
  • Start date Start date
W

Wild Bill

I have OL03 set to download headers, so I can view (with the standard
interface) and decide whether to open a message. I cobbled the following
attempt to identify the sender first, although I only really know Excel
VBA. Bear with me; I'm trying.

There are questions about the code, all beginning with "'Q" below. The
last one can be skipped, being a bit more general

Thanks in advance for your expert help. Amazing group here. Code:
Sub WhoSent()
Dim objSession As Object, mItem As MailItem, objFolder As MAPIFolder,
objMessage, objSender, iResp As Integer
If Application.ActiveExplorer.Selection.Count = 0 Then
MsgBox "Select a message to find out who sent it.",
vbInformation
Exit Sub
End If
If Application.ActiveExplorer.Selection.Count > 1 Then
MsgBox "Only the first selected message will be looked at, as
code is currently done", vbInformation
Exit Sub
End If
Set mItem = Application.ActiveExplorer.Selection.Item(1)
Set objSession = CreateObject("MAPI.Session") ' Create
MAPI session (to use GetMessage)
objSession.Logon "", "", False, False, 0 ' Logon
using an existing MAPI session
Set objFolder = mItem.Parent ' Get
folder where the current Outlook item lives

'Q1. .GetMessage opens the message itself, right?
' If so, is that the ONLY way I can get .Sender, i.e. by OPENING
the G.D. thing???
iResp = vbYes
If (mItem.UnRead) Then
iResp = MsgBox("You (possible) idiot. This is an unread item.
You nearly opened it, when here you are " _
& "concerned about who it's from." & vbCrLf _
& "Well, want to open it to see anyway?", vbYesNoCancel +
vbDefaultButton3)
If iResp <> vbYes Then Exit Sub
iResp = MsgBox("Are you REALLY sure?", vbYesNoCancel +
vbDefaultButton3)
End If
If iResp <> vbYes Then Exit Sub

Set objMessage = objSession.GetMessage(mItem.EntryID,
objFolder.StoreID) ' Get the Outlook item with CDO

'Q2. Can I suppress the following warning? 'Q3. Why does he lie
about the free 10 minutes w/o harassment?
'How about a better shortcut than left-arrow&Enter ?
'Q4. Is there a docmd.setwarns false, etc.? displayalerts? On error
doesn't accomplish anything.
On Error GoTo err1_WhoSent
Set objSender = objMessage.Sender ' Get the
sender of the message
On Error GoTo 0

MsgBox "Sender name: <" & objSender.Name & ">; Sender address: <" &
objSender.Address & ">"
'Q5. Is this a reliable, or potentially spoofed address?
'How about .sendername, which doesn't need GetMessage?
'SenderEmailAddress? Are those 2 identical except for case?
objSession.Logoff ' Close MAPI
session
Set objSession = Nothing
Exit Sub
err1_WhoSent:
MsgBox "Well, it did error out"
Exit Sub 'Q6 Is Exit redundant? Hmm, good question. Does it affect
error handling scope?
End Sub
 
#1: If that's what you mean, GeMessage doesn't display the message.

#2: In OL 03 yes, don't use CDO but the OOM itself. If you need this for OL
XP as well then use the Redemption (www.dimastr.com), please.

#4: no.

#6: Yes, on End Sub it would exit anyway / In your code no affect on the
scope.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Thu, 26 Jul 2007 04:17:21 GMT schrieb Wild Bill:
 
Thank you for examining all of my code.

For my Q1 in this thread I groped for my own answer with substituting
..SenderEmailAddress for .GetMessage. I have observed that they give
different uppercasing on some (but not all!) messages. I still wonder
(in Q5) which of the 2 might be spoofed, or are they all the same(except
for case)? Can I get a true source domain somehow?

As to my preoccupation with trying to not open the message, I don't want
a spammer to recognize that I opened it, or to set off malicious code by
opening either. (And yes, I also want it to not display.)

I assume by OOM you mean that I should use .SenderEmailAddress rather
than .GetMessage. Well, if that rids the Object Model Guard, then it
solves Q2, Q3 and Q4 - great! I still note in Q3 that when you DO do
..GetMessage, you don't get 10 minutes without the dialog; each and every
time I run the macro I get the warning, and even get no keyboard
shortcut.

On Q6, then, there's no reason "here" to precede End Sub with Exit Sub.
Are there cases where you would? I wonder if anyone has examined it
right down at the assembler level, because it would seem to me to be
"more expensive" (less efficient). In this app it's no big deal because
I'm not looping calls to the sub.
 
As Sue answered already, accessing an item's properties doesn't open it the
way like it would by displaying the message.

While the SenderEMailAddress is a property of the Outlook.MailItem and tells
you the sender's e-mail address, GetMessage is a function of the CDO 1.21
library that you use in your code to get a Mapi.Message object for an
Outlook.MailItem. You cannot really subsitute the one for the other.

The benefit of using the OOM (Outlook Object Model) in Outlook 2003 from
within Outlook is that you don't get the security dialogs, whereas by using
the CDO library the dialog pops up. Whether it really gives you 10 minutes
or whatever doesn't matter in my opinion: Simply avoid it by using the OOM
in this case.

And to Q6: Callign Exit Sub is necessary if there is more code after that.
In your case, if it's the last line before End Sub then it's not necessary.
You don't have to look down to the Assembler code to realize that :)

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>


Am Thu, 26 Jul 2007 08:38:03 GMT schrieb Wild Bill:
 
Back
Top