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

后端 未结 5 1696
[愿得一人]
[愿得一人] 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:02

    If someone's still looking for a solution to this problem, here is a simplified and true-blue VBA version of the code to handle this requirement.

    Public Sub GetCurrentItem()
        On Error Resume Next
        Set ObjSelectedItem = Outlook.ActiveExplorer.Selection.Item(1)
        If TypeName(ObjSelectedItem) = "MailItem" Then
            If ObjSelectedItem.SenderEmailType = "EX" Then
                MsgBox (ObjSelectedItem.Sender.GetExchangeUser.PrimarySmtpAddress)
            Else
                MsgBox (ObjSelectedItem.SenderEmailAddress)
            End If
        Else
            MsgBox ("No items selected (OR) Selected item not a MailItem.")
        End If
        Set ObjSelectedItem = Nothing
    End Sub
    

提交回复
热议问题