C#:将地址交换为 SMTP 或者从 Windows 联系人获取 SMTP 邮件的另一种方式?

发布于 2024-12-03 13:03:18 字数 568 浏览 0 评论 0原文

我正在尝试找到一种方法(在 C# 中)读取写入了名称的 txt 文件,然后程序应该在地址簿(Outlook 甚至 Windows 的其他地址簿)中搜索并解析该名称作为 SMTP 地址。

通过 OOM,我可以轻松到达 Exchange 格式的邮件地址,但我不知道如何处理这些地址,因为我将邮件构建为仅支持 SMTP 地址的 MailMessage 对象。

我尝试过不同的方法: 1-Microsoft.Communications.Contact:

`ContactManager cm = new ContactManager();`

`List<Contact> contatti = (List<Contact>)cm.GetContactCollection();`

第二行导致我出现 NullReferenceException。

2-CDO库:我无法获得任何东西,因为它缺少一些重要的类,例如AddressEntry。

3-MAPI库(从microsoft.com下载的CDO 1.2):只有接口,不能实例化任何东西。

有什么建议吗?

I'm trying to find a way (in C#) to read a txt file in which there's a name written, and then the program should search in the address book (of Outlook or even the others address books of Windows) and resolve that name as an SMTP address.

Via OOM i can easily reach Exchange format mail addresses, but i don't know what to do with these, since i build my mail as a MailMessage object, that only supports SMTP addresses.

I've tried different ways:
1-Microsoft.Communications.Contact:

`ContactManager cm = new ContactManager();`

`List<Contact> contatti = (List<Contact>)cm.GetContactCollection();`

The second row cause me a NullReferenceException.

2-CDO library: i can't obtain anything, because it lacks some important classes such as AddressEntry.

3-MAPI library (CDO 1.2 downloaded from microsoft.com): is only full of interfaces, can't instantiate anything.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无戏配角 2024-12-10 13:03:18

正如 Ben 所建议的,如果您的名称不明确,您可能会遇到问题。你需要为此做好准备。

除了这个问题之外,您还有两个选择: 查询 AD 信息(使用 System.DirectoryServices 或更好的 System.DirectoryServices.AccountManagement)。从返回的实体中,读取 proxyAddresses 属性。此属性包含用户或联系人的地址。

如果您运行的是 Exchange 2007 或更高版本,您还可以使用 EWS 托管 API 通过 Exchange 解析名称。使用 ResolveNamed 方法:http://msdn.microsoft.com/en-us/library/exchangewebservices.exchangeservicebinding.resolvenames(v=exchg.140).aspx

EWS 托管 API - 下载:http://www.microsoft.com/download/en/details.aspx?id=13480

EWS 托管 API - SDK:http://msdn.microsoft.com/en-us/library/dd633710(v=exchg.80).aspx

As Ben suggests, you might run into problems where the name you have is not unambiguous. You need to be prepared for this.

Apart from that issue you have two options here: Query AD for the information (using System.DirectoryServices or even better System.DirectoryServices.AccountManagement). From the entities returned, read the proxyAddresses property. This property contains the addresses of the user or contact.

If you are running Exchange 2007 or later, you can also use the EWS Managed API to resolve the name via Exchange. Use the ResolveNamed method: http://msdn.microsoft.com/en-us/library/exchangewebservices.exchangeservicebinding.resolvenames(v=exchg.140).aspx

EWS Managed API - Download: http://www.microsoft.com/download/en/details.aspx?id=13480

EWS Managed API - SDK: http://msdn.microsoft.com/en-us/library/dd633710(v=exchg.80).aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文