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
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