如何快速获取交换用户的SMTP地址? [英] How to get SMTP address for exchange user quickly?

查看:82
本文介绍了如何快速获取交换用户的SMTP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码,PrimarySmtpAddress使用50ms,需要15秒以上才能加载300个用户.我不熟悉Outlook API,似乎此属性是检索SMTP地址的常用方法,但是它太慢了.

The below is my code, the PrimarySmtpAddress use 50ms which need more than 15 s to load more 300 users. I am not familiar with Outlook API, and it seems this Property is the usual way to retrieve the SMTP address, but it is far too slow.

还有其他方法可以检索SMTP地址吗?还是我错误地使用了此属性?

Is there other way to retrieve the SMTP address or I use this property incorrectly?

.NetFramework是3.5

The .NetFramework is 3.5

Outlook版本为2010

Outlook Version is 2010

Microsoft.Office.Interop.Outlook是12.0.0.0

Microsoft.Office.Interop.Outlook is 12.0.0.0

Microsoft.Office.Interop.Outlook.NameSpace olNS = outlook.GetNamespace("MAPI");
olNS.Logon(null, null, false, true);

Microsoft.Office.Interop.Outlook.AddressLists als = olNS.AddressLists;
if (als == null) return;
Stopwatch watcher = new Stopwatch();
foreach (Microsoft.Office.Interop.Outlook.AddressList addrList in als)
{
    if (addrList.Name == "Global Contact Address" || addrList.Name == "Global Address List")
    {
        foreach (Microsoft.Office.Interop.Outlook.AddressEntry entry in addrList.AddressEntries)
        {
            if (entry == null) continue;
            if (entry.Name == null || entry.Name.Trim() == "") continue;
            if (entry.Address == null || entry.Address.Trim() == "") continue;

            eMailInfo info = new eMailInfo();
            info.Name = entry.Name;
            MailMessage msg = new MailMessage();
            watcher.Start();
            Microsoft.Office.Interop.Outlook.ExchangeUser user = entry.GetExchangeUser();
            Debug.WriteLine(string.Format("This get exchange user time {0}", watcher.ElapsedMilliseconds));
            watcher.Reset();
            if (user != null)
            {
                watcher.Start();
                info.Address = user.PrimarySmtpAddress;
                Debug.WriteLine(string.Format("This get exchange user address time {0}", watcher.ElapsedMilliseconds));
                watcher.Reset();
            }
            else
                info.Address = entry.Address;
        }
    }
}

推荐答案

检查是否有帮助

  • Account Object(Outlook) Look for Outlook.OlAccountType.olExchange in the example provided.

获取多个帐户的信息

这篇关于如何快速获取交换用户的SMTP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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