我设置了一个收件箱作为交换, hello@mycompany.com
此外,还有一个别名, news@mycompany.com
,所以所有电子邮件都发送到 news
地址最终在 hello
收件箱。
理想情况下,我希望能够使用 EWS 判断电子邮件已发送到哪个别名。
当我向 发送电子邮件时news@mycompany.com
,并使用 Microsoft Outlook 检查邮件的 Internet header , To:
标题读取 To: Hello <news@mycompany.com>
这正是我想看到的。
但是,使用 EWS,当我查看 ToRecipients 时消息的属性,报告的电子邮件地址始终是主 SMTP 地址的地址。还有 InternetMessageHeaders Webservices.Data.Item 的属性不包含 To:
属性(property)。我似乎也无法使用 EWSEditor 看到正确的地址检查消息的所有属性。
this forum post的答案似乎暗示,
...The Information about the actual email address a message is sent to is stored in the recipients collection which you can't access (outside of exportmessage) in EWS...
我将如何以编程方式执行此操作,以便我可以找到正确的
To:
地址?
最佳答案
这对我有用:
private static string GetToAddress()
{
ExchangeService exService = new ExchangeService();
exService.Credentials = new NetworkCredential("username", "password", "domain");
exService.Url = new Uri("https://youraddress/EWS/Exchange.asmx");
ExtendedPropertyDefinition PR_TRANSPORT_MESSAGE_HEADERS = new ExtendedPropertyDefinition(0x007D,MapiPropertyType.String);
PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties)
{PR_TRANSPORT_MESSAGE_HEADERS, ItemSchema.MimeContent};
FindItemsResults<Item> fiResults = exService.FindItems(WellKnownFolderName.Inbox, new ItemView(1));
foreach (Item itItem in fiResults.Items)
{
itItem.Load(psPropSet);
Object valHeaders;
if (itItem.TryGetProperty(PR_TRANSPORT_MESSAGE_HEADERS, out valHeaders))
{
Regex regex = new Regex(@"To:.*<(.+)>");
Match match = regex.Match(valHeaders.ToString());
if (match.Groups.Count == 2)
return match.Groups[1].Value;
}
return ToAddress;
}
return "Cannot find ToAddress";
}
代码来自:
http://social.technet.microsoft.com/Forums/en-au/exchangesvrdevelopment/thread/1e5bbde0-218e-466e-afcc-cb60bc2ba692
关于exchange-server - Exchange Web 服务 (EWS) API "To"别名 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6213571/