PDA

View Full Version : Get sender name from new email being composed



RyanBRZ
02-04-2016, 09:06 AM
At my company some users have multiple email addresses that they can send from. I am trying to detect which from address is selected at some point before or when the mail is sent, preferably when a file is attached to the email. Or even when the user first chooses the email address from the drop down would be best.

The ultimate goal is to populate a canned subject and body when a particular from address is used.

Using Outlook 2010 and Exchange server.

Can anyone help?

Thanks!

RyanBRZ
02-04-2016, 02:58 PM
I figured this out. I made it so once the mailbox is picked from the From dropdown, it will insert the subject and body.

For anyone else that needs this:


Public WithEvents olNewItem As Outlook.MailItem

Private Sub Application_ItemLoad(ByVal Item As Object)
If (TypeOf Item Is MailItem) Then
Set olNewItem = Item
End If
End Sub

Private Sub olNewItem_PropertyChange(ByVal Name As String)
If ((Name = "SentOnBehalfOfName") And (olNewItem.SentOnBehalfOfName = "TheMailBoxYouWant")) Then
olNewItem.Subject = "the subject"
olNewItem.HTMLBody = "the message"
End If
End Sub