使用 Redemption 获取发件人电子邮件地址的可靠方法

Reliable way of getting sender's email address using Redemption

我一直在使用 RDOMail.SenderEmailAddress 属性 在 Outlook 中获取发件人的电子邮件地址,但我最近意识到在某些情况下对于 SMTP 或 IMAP 电子邮件帐户,这 属性 null 偶尔,在电子邮件到达收件箱之后。

使用 Outlook Interop 库获取发件人电子邮件地址的方法相当复杂:https://msdn.microsoft.com/library/office/ff184624.aspx

但是,这不适用于 Redemption RDOMail 对象,因为 RDOAddressEntry 接口缺少 AddressEntryUserTypeGetExchangeUser 方法。

RDOAddressEntry 对象的文档说明了以下关于 SMTPAddress 属性 的内容:

String, read-only. Returns the SMTP address of the given user. If the address type is "SMTP", the returned value is the same as that returned by the Address property. If the address type is "EX", Redemption tries to retrieve the PR_SMTP_ADDRESS property, if unsuccessful, it retrieves the default SMTP address from the PR_EMS_AB_PROXY_ADDRESSES Extended MAPI property.

如果我在我的方法中这样做,看起来它可能是获取发件人地址的更可靠的方法:

if (rdoMail.SenderEmailAddress != null) return rdoMail.SenderEmailAddress;
if (rdoMail.Sender != null) return rdoMail.Sender.SMTPAddress;
return null;

由于我没有可靠的方法来验证我的理论,所以我在这里寻求帮助,看看是否有人有更多的经验来处理这个问题。

提前致谢。

我无法想象为什么 SenderEmailAddress 会为空,除非您有部分下载的项目(特定于 IMAP4)。没有理由使用 AddressEntryUserTypeGetExchangeUser 方法 - 您只需要地址类型 - 如果它是 "EX",则您有一个 GAL 用户,否则是一个 SMTP 地址。

要获取发件人 SMTP 地址,请检查 SenderEmailType 属性。如果不是 "EX",只需使用 SenderEmailAddress 属性。如果是 "EX",请使用 RDOMail.Fields["http://schemas.microsoft.com/mapi/proptag/0x5D01001F"] 读取 PidTagSenderSmtpAddress 属性。如果返回 null,请检查 RDOMail.Sender 是否不为 null 并阅读 RDOMail.Sender.SMTPAddress 属性.