我试图在outlook插件中获取发件人的SMTP地址 . 当我按照MSDN中的示例(如this one here)时,这可以正常工作:
private void GetSMTPAddressForRecipients(Outlook.MailItem mail)
{
const string PR_SMTP_ADDRESS =
"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
Outlook.Recipients recips = mail.Recipients;
foreach (Outlook.Recipient recip in recips)
{
Outlook.PropertyAccessor pa = recip.PropertyAccessor;
string smtpAddress =
pa.GetProperty(PR_SMTP_ADDRESS).ToString();
Debug.WriteLine(recip.Name + " SMTP=" + smtpAddress);
}
}
但是从一段时间(几周)开始参考模式
http://schemas.microsoft.com/mapi/proptag/0x39FE001E
无法解决 . Errormessage :
System.Runtime.InteropServices.COMException: http://schemas.microsoft.com/mapi/proptag/0x39FE001E Property unknown or ca not be found.
如果我在浏览器中尝试URL,我会得到:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
我能找到的所有例子(办公室2013及以上)都指向http://schemas.microsoft.com/mapi/proptag/SOMETHING的资源
我也无法在论坛或MSDN中找到任何关于此移动或更改的信息 .
还有其他人遇到这个吗?是一个已知的解决方案或workaroud .
1 回答
http://schemas.microsoft.com/mapi/proptag/0x39FE001E
不是链接,它是PropertyAccessor
对象期望的实际DASL属性名称 . 固定和命名的MAPI属性的格式不同(例如http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/85100003
) .您可以在OutlookSpy中查看MAPI属性及其DASL名称(单击IMessage按钮) .
还要记住,您不应该期望存在任何特定的MAPI属性 - 它们不能保证存在,您必须期望并处理
PropertyAccessor
对象返回的错误 .在您的特定情况下,您可以不检查发件人的SMTP地址,您正在使用邮件收件人 . 对于收件人,请检查PR_SMTP_ADDRESS属性是否存在 . 如果没有,请打开加法器条目(Recipient.AddressEntry)并从AddressEntry检查该属性 . 您还可以检查是否存在PR_EMS_AB_PROXY_ADDRESSES多值属性(返回一个数组) . 您可以尝试AddressEntry.GetExchangeUser() . PrimarySmtpAddress(准备处理错误和空值) . 再次,使用OutlookSpy查看消息,以查看存在哪个属性 .