我尝试使用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:我已经尝试了指定here的代码,但我认为它已经过时了,因为它会抛出“无法创建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
我看到你已回答了自己的问题.我会在这里发布我的C#函数,任何人都需要它,或者如果你想用它作为更多的帮助.我做你做的C#函数看起来像这样:
原文链接:https://www.f2er.com/vb/255843.htmlprivate string getSenderEmailAddress(Outlook.MailItem mail) { Outlook.AddressEntry sender = mail.Sender; string SenderEmailAddress = ""; if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry || sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry) { Outlook.ExchangeUser exchUser = sender.GetExchangeUser(); if (exchUser != null) { SenderEmailAddress = exchUser.PrimarySmtpAddress; } } else { SenderEmailAddress = mail.SenderEmailAddress; } return SenderEmailAddress; }