gpt4 book ai didi

outlook - 以编程方式从 Exchange Outlook 联系人获取 Internet 电子邮件地址?

转载 作者:行者123 更新时间:2023-12-03 22:54:26 25 4
gpt4 key购买 nike

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

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

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?

最佳答案

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

为此,您需要访问 AddressEntry通过 Recipient对象模型。检索实际收件人的唯一方法 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;
}

关于outlook - 以编程方式从 Exchange Outlook 联系人获取 Internet 电子邮件地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11326062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com