Capture Sender's Display name and Address

Status
Not open for further replies.

Ross

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server 2007
Why is this code not displaying the sender display name and email address? Is it because I'm on MS Exchange?

Option Explicit

Private Sub SendEmail()

Dim OutApp As Object
Dim OutMail As Object
Dim sBody As String
Dim sEmailBody As String
Dim sSenderName As String
Dim sSenderEmail As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

sEmailBody = "Testing"

With OutMail
.To = "test@yahoo.com"
.Subject = "Test"
.display
End With

sBody = OutMail.HTMLBody

With OutMail
.HTMLBody = sEmailBody & sBody
.display
End With

sSenderName = OutMail.sendername
sSenderEmail = OutMail.sendername

Debug.Print "Name: " & sSenderName _
& Chr(10) & "Email: " & sSenderEmail

Set OutMail = Nothing
Set OutApp = Nothing

End Sub
 
Not really because of exchange - but because senderemail is incoming and the name and address aren't set when you prepare a message.

You can get the values as the message is sent (using an itemsend macro) :

sSenderName = OutMail.SendUsingAccount
sSenderEmail = OutMail.SenderEmailAddress
Debug.Print "Name: " & OutMail.SendUsingAccount & _
Chr(10) & "Email: " & OutMail.SenderEmailAddress
 
This will get you the account name and address - which in current versions, is the email address for both when you use Exchange - it can be changed for pop and imap.

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

Debug.Print Item.SendUsingAccount
Debug.Print Item.SenderEmailAddress

End Sub
 
Thank you. This will work.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
L Capture email addresses and create a comma separated list Outlook VBA and Custom Forms 5
M Using field names to capture a data element Using Outlook 0
I Capture incoming emails Outlook VBA and Custom Forms 1
A Capture network traffic in IE to file Outlook VBA and Custom Forms 5
JorgeDario How to capture and save the text, when responding a MailItem? Outlook VBA and Custom Forms 3
G Capture "forward event" ? Outlook VBA and Custom Forms 11
J VBA Form in Outlook to capture data and complile a mail Outlook VBA and Custom Forms 2
A how to capture events for next item Outlook VBA and Custom Forms 10
B Capture Inbound E-mail Subject with VBA Outlook VBA and Custom Forms 4
R How to capture a Mailitem Event Outlook VBA and Custom Forms 3
A how to capture outlook 2007 events Outlook VBA and Custom Forms 4
T Some way to capture who marks an email as read Outlook VBA and Custom Forms 1
C Event Capture - Item Context Menu (Delete). Can you hook it? Outlook VBA and Custom Forms 1
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0
C Outlook 365 Copy/Save Emails in Folder Outside Outlook to Show Date Sender Recipient Subject in Header Using Outlook 0
L Checking Sender Email Address for trusted domain from list on intranet Outlook VBA and Custom Forms 4
F Forward incoming email with 4 embedded images in the body without original sender Outlook VBA and Custom Forms 22
T Junk Email does not get added to the Blocked Sender List Using Outlook 0
M How create a Rule to filter sender's email with more that one @ sign Using Outlook 1
F Junk Email does not get added to the Blocked Sender List Using Outlook 4
U Outlook 2016 Outlook 2016 sender name Using Outlook 1
C Macro to extract sender name & subject line of incoming emails to single txt file Outlook VBA and Custom Forms 3
Terry Sullivan Sender's Name Doesn't Appear in the From Field on Outlook 365/IMAP Using Outlook 2
K Use VBA to find Sender and Recipient from Microsfot 365 Journaled Email Items Outlook VBA and Custom Forms 3
Terry Sullivan Sender Field Displays My E-Mail Address, Not My Name Using Outlook 1
J Autoreply email recieved from specific sender after deleting some text from body. Using Outlook 0
D Reply with a template loose the sender's embedded image Outlook VBA and Custom Forms 0
J Outlook 2016 How tell Outlook not to trust sender? Using Outlook 1
M Screen Scrape Sender IP Address Outlook VBA and Custom Forms 6
S Meeting Invite arrives from Wrong ("send-as") Sender Using Outlook 1
icacream Rule based on sender / wrong sender sent to folder Using Outlook 7
D Moving Emails Based on Recipient/Sender Outlook VBA and Custom Forms 4
B Looking to filter (or just find/search) for only messages that the sender has sent more than 1 messa Using Outlook 2
I How to display sender's name instead of email address in outlook 2013 message Using Outlook 5
A Sort emails into subfolders based on sender and deleting emails automatically Outlook VBA and Custom Forms 3
C Display Sender As Contact Outlook VBA and Custom Forms 4
Ed Sheehan Unusual behaviour in setting Sender (Outlook 2016) Outlook VBA and Custom Forms 4
J Auto Forward - Include Attachment and change Subject depending on original sender Outlook VBA and Custom Forms 3
Q Undisclosed recipients does not include sender Using Outlook 1
M Move new mail to folder based on sender address Outlook VBA and Custom Forms 2
D Inserting sender name and address with vba Outlook VBA and Custom Forms 1
M Blocked Sender List @Domain Not Working Using Outlook 0
P MS OUTLOOK 2013 - Adding Sender on the CC line Using Outlook 5
J Saving attachments from specific sender (phone number) to specific folder on hard drive Using Outlook 3
B Can't expose sender email address when linking outlook to access Using Outlook 3
Diane Poremsky Use VBA to create an Outlook Search Folder for Sender Using Outlook 0
K Extract email to excel from a specific sender Outlook VBA and Custom Forms 3
D Change sender name outlook vba 2010 Custom Userform Outlook VBA and Custom Forms 1
O See recent emails from a sender Using Outlook 2

Similar threads

Back
Top