C#-在Web应用程序中访问Outlook通讯录 [英] C# - access Outlook address book in web app

查看:171
本文介绍了C#-在Web应用程序中访问Outlook通讯录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在ASP.NET MVC C#中开发一个Web应用程序,您可以在其中创建公司每年发送的自动电子邮件.

I am developing a webapp in ASP.NET MVC C# where you can create automated emails that are sent out in the company yearly.

我正在寻找一种方法来验证用户指定的收件人地址是否有效并存在于公司中. 我认为可以通过查找Outlook的通讯簿来完成此操作,因为它包含公司中的所有电子邮件地址.

I am looking for a way to verify that the To-addresses specified by the user are valid and exist in the company. I thought this could be accomplished by looking up Outlook's address book, since it contains all email addresses in the company.

我到处搜索并找到 https://msdn.microsoft.com /en-us/library/ff184631.aspx ,建议使用Microsoft.Office.Interop.Outlook软件包.但是,据我所知,使用此软件包需要安装Outlook应用程序.我想这对于在服务器上运行的解决方案可能是有问题的.

I have searched around and found https://msdn.microsoft.com/en-us/library/ff184631.aspx which suggests using the Microsoft.Office.Interop.Outlook package. However, as far as I can see, using this package requires that the Outlook application is installed. I suppose this can be problematic for a solution that runs on a server.

我可以使用Microsoft.Office.Interop.Outlook软件包来实现我的目标,还是需要使用另一种更好地支持服务器的方法?

Can I use the Microsoft.Office.Interop.Outlook package to accomplish my goal, or do I need to use another method that better supports a server?

推荐答案

在注释中遵循Filburt的提示,我发现这段代码可以实现我的目标

Following the tip of Filburt in the comments, I found this code piece that accomplishes my goal

https://code.msdn.microsoft .com/windowsdesktop/A-very-simple-example-to-8bbe95f0

它在Active Directory中查找. 我已将代码从链接简化为以下内容.在此示例中,我们检查AD中是否存在电子邮件地址addyToCheck@domain.com:

It looks up in Active Directory. I have simplified the code from the link to the following. In this example we check if the email address addyToCheck@domain.com exists in the AD:

using System.DirectoryServices;

// check if address exists
var searcher = new DirectorySearcher();
searcher.Filter = "(&(mail=" + "addyToCheck@domain.com" + "))";
if (searcher.FindOne() != null) {
    // the email exists in AD - all good!
}

这在本地对我有效,我想它也会在服务器上起作用.如果您发现任何问题,请告诉我.谢谢.

This works for me locally and I suppose it will on the server as well. Let me know if you see anything wrong. Thank you.

这篇关于C#-在Web应用程序中访问Outlook通讯录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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