How can I get the sender email address using Outlook.MailItem in VB.NET?

后端 未结 5 1688
[愿得一人]
[愿得一人] 2020-12-08 11:57

I have tried using mailItem.SenderEmailAddress and mailItem.Sender.Address but they both return a string that looks like this:

/O=DO

5条回答
  •  粉色の甜心
    2020-12-08 12:10

    Created a VBA function if you wanted to use it for simplicity. A sample call would be Left(GetEmailAddress(mai) & Space(50), 50) where mai is expected to be a MailItem object. Used and tested successfully in Microsoft Outlook 2010

    Public Function GetEmailAddress(mai As Object) As String
        On Error Resume Next
        Set ObjSelectedItem = mai
        If TypeName(ObjSelectedItem) = "MailItem" Then
            If ObjSelectedItem.SenderEmailType = "EX" Then
                GetEmailAddress = ObjSelectedItem.Sender.GetExchangeUser.PrimarySmtpAddress
            Else
                GetEmailAddress = ObjSelectedItem.SenderEmailAddress
            End If
        Else
            GetEmailAddress = "Not a MailItem"
        End If
    
        Set ObjSelectedItem = Nothing
        End Function
    

提交回复
热议问题