以编程方式从Exchange Outlook联系人获取Internet电子邮件地址吗? [英] Getting the Internet e-mail address from an Exchange Outlook Contact programmatically?

查看:222
本文介绍了以编程方式从Exchange Outlook联系人获取Internet电子邮件地址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I’m trying to read out the Internet formatted address from an Exchange connected Outlook. I read all contacts from the Outlook Contacts, i.e. not from the Global Address Book (GAB), and the problem is that for all users that are stored in Contacts from the Exchange GAB I’ve only managed to read out the X.500 formatted address which is not useful in this case. For all manually added contacts that are not in the domain of the Exchange server, the Internet address is exported as expected.

基本上,我使用以下代码段来枚举联系人:

Basically I’ve used the following code snippet to enumerate the Contacts:

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();
}

有什么方法可以代替X.500提取Internet地址吗?

Is there any way to extract the Internet address instead of the X.500?

推荐答案

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

You need to convert from ContactItem to AddressEntry - one email address at a time.

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

To do this, you need to access the AddressEntry via the Recipient object model. The only way to retrieve the actual Recipient EntryID is by 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;
}

这篇关于以编程方式从Exchange Outlook联系人获取Internet电子邮件地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆