尝试从所有AppointmentItem收件人获取SMTP地址

时间:2018-10-13 08:18:06

标签: vsto outlook-addin

我迭代所有AppointmentItem.Recipients。对于每个收件人,我使用以下实用程序方法来检索收件人的“常规” SMTP电子邮件地址:

为此,我使用了stackoverflow发布的内容:Getting email address from a Recipient object

    public static string GetSmtpAddress(Outlook.AddressEntry addressEntry)
    {
        String smtpAddress;

        if (addressEntry.Type == "EX")
        {
            if (addressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry
                 || addressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
            {
                Outlook.ExchangeUser user = addressEntry.GetExchangeUser();
                smtpAddress = user != null ? user.PrimarySmtpAddress : null;
            }
            else if (addressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olOutlookContactAddressEntry)
            {
                //returns the actual contact but it has 3 email properties (Email1Address, Email2Address, Email3Address). 
                //How to identify which email has the user selected

                Outlook.ContactItem cont = addressEntry.GetContact();
                String OABID = addressEntry.ID;
                String typ = OABID.Substring(29 * 2, 2);
                if (typ=="00")
                {
                    smtpAddress = cont.Email1Address; <!-- Strange Emailadress
                }else if (typ=="01")
                {
                    smtpAddress = cont.Email1Address;
                } else
                {
                    smtpAddress = cont.Email2Address;
                }
            } else
            {
                smtpAddress = "";
            }
        }
        else if (addressEntry.Type == "SMTP")
        {
            smtpAddress = addressEntry.Address;
        }
        else
        {
            smtpAddress = "";
        }
        return smtpAddress;
    }

标记为<-Strage Email的行检索到一个看起来很奇怪的电子邮件地址:看起来/ o = Exchange xxxxx xxxx ..最后,它还包含smtp地址。

我要搜索的是100%健壮的实用程序功能,无论收件人是哪种地址类型(Exchange用户,AddressBook用户或其他),都可以检索正确的SMTP地址。任何帮助都非常感谢。

最好的问候 汉尼斯

1 个答案:

答案 0 :(得分:1)

如果GAL条目不再存在,则所有投注均关闭。在甚至触摸Recipient.AddressEntry之前,请检查收件人表中SMTP地址是否可用-使用Recipient.PropertyAccessor.GetProperty来读取PR_SMTP_ADDRESS属性(DASL名称"http://schemas.microsoft.com/mapi/proptag/0x39FE001F")。如果不存在,请读取PR_ADDRTYPE属性("http://schemas.microsoft.com/mapi/proptag/0x3002001F")-这等效于Type对象的AddressEntry属性,不幸的是Recipient对象会这样做不暴露。如果它是“ SMTP”,则只需使用Recipient.Address属性。并且只有在不是这样的情况下,才可以使用需要Recipient.AddressEntry的函数。

通过OutlookSpy(clic kIMessage按钮,转到GetRecipeintTable选项卡)查看约会,以检查PR_SMTP_`ADDRESS属性是否可用