我尝试过使用mailItem.SenderEmailAddress
,mailItem.Sender.Address
但它们都返回一个如下所示的字符串:
/O=DOMAINNAME/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHI43SPCLT)/CN=RECIPIENTS/CN=JOE BLOGGS8C3
在现实中我想joebloggs@domainname.co.uk
被退回的地方。
有人有想法么?
非常感谢。
编辑:我做了一些挖掘;它非常适用于“SenderEmailType”SMTP 的电子邮件地址,但它不适用于 Exchange 电子邮件地址。
编辑 2:我已经尝试过这里指定的代码,但我认为它已经过时,因为它会引发“无法创建 Active-X 组件”错误。
编辑 3: 对于任何和我有同样问题的人,我找到了答案(在 C# 中,转换为 VB.NET,但仍然有效):
Private Function GetSenderSMTPAddress(mail As Outlook.MailItem) As String
Dim PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
If mail Is Nothing Then
Throw New ArgumentNullException()
End If
If mail.SenderEmailType = "EX" Then
Dim sender As Outlook.AddressEntry = mail.Sender
If sender IsNot Nothing Then
'Now we have an AddressEntry representing the Sender
If sender.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry OrElse sender.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry Then
'Use the ExchangeUser object PrimarySMTPAddress
Dim exchUser As Outlook.ExchangeUser = sender.GetExchangeUser()
If exchUser IsNot Nothing Then
Return exchUser.PrimarySmtpAddress
Else
Return Nothing
End If
Else
Return TryCast(sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS), String)
End If
Else
Return Nothing
End If
Else
Return mail.SenderEmailAddress
End If
End Function