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