Exchange Web Services (EWS) API “To” header for alias

前端 未结 1 1926
夕颜
夕颜 2020-12-06 11:55

I have an inbox set up in exchange, hello@mycompany.com

Additionally, there is an alias for this, news@mycompany.com

相关标签:
1条回答
  • 2020-12-06 12:42

    This works for me:

        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";
        }
    

    The code is from: http://social.technet.microsoft.com/Forums/en-au/exchangesvrdevelopment/thread/1e5bbde0-218e-466e-afcc-cb60bc2ba692

    0 讨论(0)
提交回复
热议问题