Get email address message was sent to on Application_ItemSend
-
Tuesday, April 10, 2012 10:00 PM
Hello,
I need some code that gets me the email address that the message was received by, at the Application_ItemSend trigger.
I was hoping something like the below would work but it doesnt seem to.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim oMail As MailItem Set oMail = Item MsgBox oMail.ReceivedByName
If someone could help me with this code it would be appreciated.
Thank you.
All Replies
-
Friday, April 13, 2012 6:34 AMModerator
Hi,
Try this code to see whether it hit the mark.
Sub send_add()
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim MsgTxt As String
Dim x As Integer
Set myOlExp = Application.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
MsgBox myOlSel.Item(x).SenderEmailAddress
Next x
End SubJaynet Zhang
TechNet Community Support
-
Friday, April 13, 2012 6:51 AM
@Jaynet
Thank you for your reply.
Maybe I did now make my request clear enough.
I want it to execute in an email on the Application_ItemSend event, and I want it to give me the email address the message was received by not received from.
So if a message was recieved from joe@example.com , sent to bill@example.com, (ME) when i send my reply, it would pop up and display 'bill@example.com'
so i know which email account i received the message on.
This may sound stupid and you may ask why I want to do this... it is part of another script I am building for a particular purpose.
thanks
-
Tuesday, April 17, 2012 1:09 AMModerator
Hi,
I am afraid that the ReceivedByName is null before sending a mail.
So let’s try to use the following code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objNS As Outlook.NameSpace
Set objNS = Outlook.GetNamespace("MAPI")
MsgBox objNS.Session.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress
End Sub
Jaynet Zhang
TechNet Community Support
-
Tuesday, April 17, 2012 3:19 AM
Hello,
Thank you for your reply, and it does work, however it's not quite what I am looking for.
This is what's happening:
Pop mail address pop@example.com forwards to hosted exchange (exchange@example.com)
The mail is recieved to outlook using exchange@example.com , but still shows pop@example.com in the 'To' field, as that was the address the message was sent to.
I want a script that when reply to the email, (replying from exchange@example.com) it pops up and tells me that the mail was sent to pop@example.com (the address in the 'To' field on the recieved mail item.
Does this make sense?
Thanks
-
Thursday, April 19, 2012 1:59 AMModerator
Hi,
Now, I think that waht you want is the address in the “To:” textbox. That is to say, you want the receiver’s address. Am I right?
Check the following code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim oMail As MailItem
Set oMail = Item
Dim recCount As Integer
Dim myRec As Outlook.Recipient
Dim myAddress As String
recCount = oMail.Recipients.Count
For i = 1 To recCount
Set myRec = oMail.Recipients(1)
myAddress = myRec.Address
MsgBox myAddress
Next
End Sub
Jaynet Zhang
TechNet Community Support
- Marked As Answer by Jaynet ZhangMicrosoft Contingent Staff, Moderator Monday, April 23, 2012 1:24 AM

