始终返回Outlook收件人的SMTP电子邮件地址

时间:2019-09-20 20:18:56

标签: vba outlook mapi

我在这里看到了一些帖子,要求人们查找收件人的电子邮件地址并被引用到MAPI属性:http://schemas.microsoft.com/mapi/proptag/0x39FE001E“。但是,正如某些用户指出的那样,并非所有MAPI属性都可以得到保证因此,我正在寻求开发一种功能,以找到获取此电子邮件地址的正确方法。对于发件人的电子邮件地址,我能够确定其是否为交换用户并取回SMTP电子邮件地址。不管MAPI是否丢失,都可以在这里返回?

这是我到目前为止所拥有的

Public Function RecipientSMTPEmailAddress(outRecip As Outlook.Recipient) As String

On Error GoTo MissingMAPIError
RecipientSMTPEmailAddress = outRecip.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")

Exit Function
MissingMAPIError:

RecipientSMTPEmailAddress = outRecip.Address

End Function

我正在寻找一种类似于用于发件人信息的方法:

 If OutMail.SenderEmailType = "EX" Then
      SenderInfo = OutMail.Sender.GetExchangeUser.PrimarySmtpAddress
 Else
      SenderInfo = OutMail.SenderEmailAddress
 End If

如果有更好的方法来确保我能收到我的SMTP电子邮件地址,

* 2019年9月23日编辑-改进并改进了代码以捕获所有收件人错误

Public Function RecipientSMTPEmailAddress(outRecip As Outlook.Recipient) As String

On Error GoTo MissingMAPIError

RecipientSMTPEmailAddress = outRecip.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")

Exit Function

MissingMAPIError:

RecipientSMTPEmailAddress = RecipientSMTPEmailAddressExchange(outRecip)

End Function
Public Function RecipientSMTPEmailAddressExchange(outRecip As Outlook.Recipient) As String

On Error GoTo MissingExchangeError

RecipientSMTPEmailAddressExchange = outRecip.AddressEntry.GetExchangeUser.PrimarySmtpAddress

Exit Function

MissingExchangeError:

RecipientSMTPEmailAddressExchange = ""

End Function

1 个答案:

答案 0 :(得分:0)

如果缺少PR_SMTP_ADDRESS属性,请使用Recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddrress(准备处理null和异常)。