如何通过Exchange Web服务获取真实的电子邮件地址? [英] How do I get the real email address with Exchange web services?

查看:223
本文介绍了如何通过Exchange Web服务获取真实的电子邮件地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Exchange Web服务获取电子邮件发件人的真实电子邮件地址,但是mailitem.Sender.Address包含类似-

I am trying to get the real email address of the sender of an email using Exchange web services, however the mailitem.Sender.Address contains something like -

/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (...........)/CN=RECIPIENTS/CN=...........-.....

如何获取此电子邮件发件人的真实电子邮件地址?

How can I get to the real email address of the sender of this email?

我的代码:

Dim sf As SearchFilter = New SearchFilter.SearchFilterCollection(LogicalOperator.And, New SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, False))
Dim findResults As FindItemsResults(Of Item) = service.FindItems(WellKnownFolderName.Inbox, sf, New ItemView(128))
Dim items As ServiceResponseCollection(Of GetItemResponse) = service.BindToItems(findResults.Select(Function(item) item.Id), New PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients))

For Each itItem As Microsoft.Exchange.WebServices.Data.Item In findResults.Items
      If TypeOf itItem Is EmailMessage Then
            Dim mailItem As EmailMessage = DirectCast(itItem, EmailMessage)

然后我要引用mailItem.Sender.Address,其中包含上述字符串而不是abc@whatever.com

And then I want to refer to mailItem.Sender.Address, which contains the above mentioned string instead of abc@whatever.com

有些示例代码(最好是在VB.NET中),将不胜感激,因为我很难弄清这些Exchange Web服务的工作方式.

Some example code, preferably in VB.NET, would be appreciated as I have a hard time figuring out how these Exchange web services work.

推荐答案

我想回答我自己的问题:

I'd like to answer my own question:

Dim instances As NameResolutionCollection
instances = service.ResolveName(mailItem.Sender.Address)
If instances.Count > 0 Then
    ResolveName = instances(0).Mailbox.Address
Else
    ResolveName = ""
End If

...其中服务"是一个ExchangeService对象,而mailItem.Sender.Address包含一个X500地址(我认为这就是所谓的地址).如Jan Doggen指出,如果发件人是您组织的实习生,mailItem.Sender.Address将包含X500类型的地址.

... where "service" is an ExchangeService object and mailItem.Sender.Address contains an X500 address (I think that's what it's called). mailItem.Sender.Address will contain an X500 type address if the sender is intern to your organisation as Jan Doggen pointed out.

我可能建议更改为以下内容:

I might recommend changing to the following:

If instances.Count > 0 Then
    ResolveName = instances(0).Mailbox.Address
Else
    ResolveName = i.Sender.Address
End If

通过此操作,如果电子邮件来自外部来源,则ResolveName将保留原始发件人的电子邮件地址.

By doing this the ResolveName will keep the original sender Email Address if the email is from an external source.

这篇关于如何通过Exchange Web服务获取真实的电子邮件地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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