Question

I've written a Macro in Outlook 2013 where I need to retrieve the sender email address as a string

A simple version is

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim oMail As MailItem
Set oMail = Item

Dim sender as String
sender = oMail.SenderEmailAddress 

End Sub 

The above works great.

I now have added a new email account to Outlook and this is where the issue is.

If I create a new email it uses my default@mail.com email address. If I then change the account from which to send the email from (to myOtherAccount@mail.com), the SenderEmailAddress within the VBa does not reflect this change... It still shows (in the watch window) as default.mail.com

How can I get Outlook to re-check the sender (as I assume it's caching it some where)?

Was it helpful?

Solution

All sender related properties are set after the ItemSend event fires. The earliest you can see sender properties is when the Items.ItemAdd event fires on the Sent Items folder.

OTHER TIPS

Just define your folder in the application:startup

Public Sub Application_Startup()

Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentbox)

End Sub

Then just change your code above to the itemAdd Event like

Private Sub myFolder_ItemAdd(ByVal item As Object)

Try this:

senderEmail = Item.SendUsingAccount

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top