【问题标题】:Getting contacts from Exchange instead of Outlook从 Exchange 而不是 Outlook 获取联系人
【发布时间】:2020-09-12 17:21:39
【问题描述】:

我目前正在开发一个仅在工作中在内部使用的应用程序。我需要获取当前登录用户的联系人以在应用程序中使用,我目前正在获取以下联系人:

Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace NameSpace = app.GetNamespace("MAPI");
            Microsoft.Office.Interop.Outlook.MAPIFolder ContactsFolder = NameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
            Microsoft.Office.Interop.Outlook.Items ContactItems = ContactsFolder.Items;
            foreach (Microsoft.Office.Interop.Outlook.ContactItem item in ContactItems)
            {

                //do stuff with the contacts here

            }

这种方法的问题在于,每当用户打开应用程序但 Outlook 尚未打开时,就会出现一个 Outlook 弹出窗口,要求用户允许或拒绝应用程序访问 Outlook 联系人。这是不必要的,我唯一想到的如何阻止这种形式的发生不是使用 Outlook 本身,而是从 Exchange Server 获取联系人。

我已经查看了诸如 EWS 之类的大量文档,但是我没有找到 EWS 的参考资料可以保证与 Exchange 2019 一起使用。我还希望根据当前登录用户的域身份验证自动完成任何身份验证要求用户输入密码。

我确实尝试过使用它:https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/get-started-with-ews-managed-api-client-applications 但是ExchangeVersion 只有 Exchange 2013 的选项。

我应该使用什么来实现这一点?任何朝着正确方向的推动将不胜感激。

【问题讨论】:

    标签: c# asp.net outlook exchange-server exchange-server-2019


    【解决方案1】:

    您收到安全提示是因为您的计算机没有最新的防病毒应用程序。

    如果您无法控制应用运行的环境,您唯一的选择是扩展 MAPI(C++ 或 Delphi)或Redemption(任何语言)。

    请记住,Outlook 对象模型无法在 Windows 服务(例如 IIS)中运行 - 您需要切换到 EWS、Extended MAPI 或 Redemption(使用其 RDO 对象系列)。

    【讨论】:

    • 我确实发现有人说这个弹出窗口的原因是没有最新的防病毒软件,但是我绝对这样做了,我不确定为什么它仍然会出现。我正在使用最新的帕洛阿尔托陷阱。这也是我在问题中所说的应用程序,而不是服务。
    • Windows 可能看不到该 AV 应用程序。
    【解决方案2】:

    使用active directory 而不是EWS 来获取网络用户数据,包括电子邮件地址。
    相关的命名空间是:System.DirectoryServices
    这是我在项目中编写的一个示例,用于从 AD 获取用户数据,包括按名字和姓氏的电子邮件。
    注意ActiveDirectoryEntity我们是我的一类。
    另外,关于您在问题中写的另一个问题,不需要输入用户和密码,因为当用户向 Windows 进行身份验证时,身份验证已经完成。

    public static List<ActiveDirectoryEntity> GetActiveDirectoryData(string sname, string fname)
    {
        try
        {
            DirectorySearcher search = new DirectorySearcher();
            search.Filter = String.Format("(&(objectCategory=person)(objectClass=user)(givenname={0}*)(sn={1}*))", sname, fname);
            search.PropertiesToLoad.Add("givenName");
            search.PropertiesToLoad.Add("sn");
            search.PropertiesToLoad.Add("mail");
            search.PropertiesToLoad.Add("mobile");
            search.PropertiesToLoad.Add("department");
    
            var result = search.FindAll();
    
            List<ActiveDirectoryEntity> resultlist = new List<ActiveDirectoryEntity>();
    
            foreach (SearchResult r in result)
            {
                if (r.Properties["mail"] != null)
                {
                    if (r.Properties["mail"].Count > 0)
                    {
                        ActiveDirectoryEntity ade = new ActiveDirectoryEntity();
                        if ((r.Properties["givenname"].Count > 0))
                            ade.FirstName = r.Properties["givenName"][0].ToString();
                        if ((r.Properties["sn"].Count > 0))
                            ade.LastName = r.Properties["sn"][0].ToString();
                        if ((r.Properties["mail"].Count > 0))
                            ade.Email = r.Properties["mail"][0].ToString();
                        if ((r.Properties["department"].Count > 0))
                            ade.Department = r.Properties["department"][0].ToString();
                        resultlist.Add(ade);
                    }
                }
            }
    
            return resultlist;
        }
        catch
        {
            return null;
        }
    
    }
    

    【讨论】:

    • 我不是要获取用户的广告数据。我知道如何得到。我正在尝试从 Exchange 获取他们存储的联系人。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多