【问题标题】:Getting the Internet e-mail address from an Exchange Outlook Contact programmatically?以编程方式从 Exchange Outlook 联系人获取 Internet 电子邮件地址?
【发布时间】:2012-07-10 00:03:39
【问题描述】:

我正在尝试从连接 Exchange 的 Outlook 中读取 Internet 格式的地址。我从 Outlook 联系人中读取了所有联系人,即不是从全局通讯簿 (GAB) 中读取的,问题是对于存储在 Exchange GAB 中的联系人中的所有用户,我只能读取 X.500 格式在这种情况下没有用的地址。对于不在 Exchange 服务器域中的所有手动添加的联系人,将按预期导出 Internet 地址。

基本上我已经使用以下代码 sn-p 来枚举联系人:

static void Main(string[] args)
{
    var outlookApplication = new Application();
    NameSpace mapiNamespace = outlookApplication.GetNamespace("MAPI");
    MAPIFolder contacts = mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderContacts);

    for (int i = 1; i < contacts.Items.Count + 1; i++)
    {
        try
        {
            ContactItem contact = (ContactItem)contacts.Items[i];
            Console.WriteLine(contact.FullName);
            Console.WriteLine(contact.Email1Address);
            Console.WriteLine(contact.Email2Address);
            Console.WriteLine(contact.Email3Address);
            Console.WriteLine();
        }
        catch (System.Exception e) { }
    }
    Console.Read();
}

有没有办法提取 Internet 地址而不是 X.500?

【问题讨论】:

    标签: outlook


    【解决方案1】:

    您需要将ContactItem 转换为AddressEntry - 一次一个电子邮件地址。

    为此,您需要通过Recipient 对象模型访问AddressEntry。检索实际收件人EntryID 的唯一方法是通过leveraging the PropertyAccessor of the ContactItem

    const string Email1EntryIdPropertyAccessor = "http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/80850102";
    string address = string.Empty;
    Outlook.Folder folder = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts) as Outlook.Folder;
    foreach (var contact in folder.Items.Cast<Outlook.ContactItem>().Where(c=>!string.IsNullOrEmpty(c.Email1EntryID)))
    {
        Outlook.PropertyAccessor propertyAccessor = contact.PropertyAccessor;
        object rawPropertyValue = propertyAccessor.GetProperty(Email1EntryIdPropertyAccessor);
        string recipientEntryID = propertyAccessor.BinaryToString(rawPropertyValue);
        Outlook.Recipient recipient = this.Application.Session.GetRecipientFromID(recipientEntryID);
        if (recipient != null && recipient.Resolve() && recipient.AddressEntry != null)
            address = recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress;
    }
    

    【讨论】:

    • 这个问题已经有一段时间了。你能指导我如何修改上面的代码以获得Email2EntryIDEmail3EntryID吗?我一直在互联网上寻找他们的 GUID(看起来这将是唯一的区别),但还没有找到。
    • 没关系。在我发布我的问题的那一刻,我找到了一个包含两个 ID 的 Microsoft 页面。对于任何对此感兴趣的人,只需将最后一部分 (80850102) 更改为 Email2 的 80950102 和 Email3 的 80A50102。
    猜你喜欢
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    • 2018-10-27
    相关资源
    最近更新 更多