VSTO收件人属性PR_SMTP_ADDRESS未知或找不到

问题描述

我正在尝试解析电子邮件中的所有收件人(获取姓名和电子邮件)。到目前为止,该代码工作正常。我考虑了不同的可用类型,例如EX,SMTP,EX通讯组列表或本地通讯组列表。都有自己的处理方式。

现在,我遇到一种奇怪的情况,一个特定的Exchange安装无法解析属性“ 0x39FE001F”。 仅对内部Exchange用户失败错误

The property "http://schemas.microsoft.com/mapi/proptag/0x39FE001F" is unkNown or not found.

也称为“ PR_SMTP_ADDRESS”。

在获得下面的代码之前,我尝试处理这些类型,如果其他所有方法都失败,请执行以下操作:

        var propertyName = currentMail.Recipients[i].PropertyAccessor.GetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x3001001F");
        var propertyEmail = currentMail.Recipients[i].PropertyAccessor.GetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x39FE001F");

属性0x3001001F确实得到解决,而0x39FE001F 失败

在我使用receive.GetExchangeUser()处理EX类型之前,该实例返回了null,因此我切换到属性用法。我自己无法重现上述错误,因此不会使事情更容易测试。我的理解是,它可能与Exchange缓存模式有关,但是我不确定如何在该实例中检索SMTP地址。

如何仍然可以检索SMTP地址?

更新

问题仅限于内部自动填充收件人。在这种情况下,下面的代码被触发,当addressEntry类型等于“ EX”时,将在这些行之前进行检查。

var exchangeUser = addressEntry.GetExchangeUser();

    if (exchangeUser != null)
    {
        return new List<RecipientDTO>() { new RecipientDTO() { Mail = exchangeUser.PrimarySmtpAddress,Name = exchangeUser.Name,RecipientType = type } };
    }
    else
    {
        var propertyName = addressEntry.PropertyAccessor.GetPropertySafe("0x3001001F"); 
        var propertyEmail = addressEntry.PropertyAccessor.GetPropertySafe("0x39FE001F"); //PR_SMTP_ADDRESS  
    
        Debug.WriteLine($"Recipient: EX 1,{propertyEmail}");
    
        if (propertyEmail == null)
        {
            propertyEmail = addressEntry.PropertyAccessor.GetPropertySafe("0x800F101F"); //PR_EMS_AB_PROXY_ADDRESSES 
    
            Debug.WriteLine($"Recipient: EX 2,{propertyEmail}");
        }
        
        return new List<RecipientDTO>() { new RecipientDTO() { Mail = propertyEmail,Name = propertyName,RecipientType = type } };
    }

解决方法

不能保证没有MAPI属性存在,如果发生这种情况,您需要期望并处理该异常。

如果您使用OutlookSpy来查看该特定消息,您是否可以实际看到该属性(单击IMessage按钮,转到GetRecipientTable选项卡)?