exchange-server - Exchange Web 服务 (EWS) API "To"别名 header

标签 exchange-server exchange-server-2007 exchangewebservices ews-managed-api

我设置了一个收件箱作为交换, 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/

相关文章:

rest - Microsoft Exchange 2007 是否有 REST API?

java - 使用 Java + Exchange 2007 EWS 进行单点登录

c# - 未从 Godaddy Hosted Exchange 收到 Exchange 2007 推送通知

c# - 通过 EWS 托管 API 与 Exchange Online 交谈时刷新访问 token

java - Office 365 EWS 日历访问给予 ErrorTooManyObjectsOpened

java - 将电子邮件从本地文件系统恢复到 ews api 中的 Exchange 帐户

microsoft-graph-api - 存档邮箱的Graph API失败

gmail - POP3、IMAP 和 Exchange 之间有什么区别?

powershell - 由于组策略,Powershell脚本 'Basic Authentication'无法在服务器VM上运行。我如何使用OAuth绕过此

exchange-server - Exchange Web服务: Finding emails sent to a recipient