Exchange Web服务(EWS)API“收件人"别名标题 [英] Exchange Web Services (EWS) API "To" header for alias

查看:248
本文介绍了Exchange Web服务(EWS)API“收件人"别名标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个收件箱作为交换, hello@mycompany.com

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

此外,还有一个别名 news@mycompany.com ,因此所有发送到 news 地址的电子邮件都以 hello 收件箱.

Additionally, there is an alias for this, news@mycompany.com, so all emails to the news address end up in the hello inbox.

理想情况下,我希望能够使用EWS判断电子邮件已发送至哪个别名.

Ideally, I want to be able to tell which alias an email has been sent to, using EWS.

当我向 news@mycompany.com 发送电子邮件并使用Microsoft Outlook检查邮件的Internet标头时, To: 标头显示为 ,这正是我想要看到的.

When I send an email to news@mycompany.com, and examine the Internet headers of the message using Microsoft Outlook, the To: header reads To: Hello <news@mycompany.com> which is exactly what I want to see.

但是,当我查看 InternetMessageHeaders 属性不包含 To: 属性.使用 EWSEditor 检查邮件的所有属性时,我似乎也看不到正确的地址.

However, using EWS, when I look at the ToRecipients property of the message, the reported email address is always that of the primary SMTP address. Also the InternetMessageHeaders property of the Webservices.Data.Item does not contain the To: property. I also can't seem to see the correct address using EWSEditor to examine all the properties of the message.

此答案论坛帖子似乎暗示了这一点,

...有关邮件发送到的实际电子邮件地址的信息存储在收件人集合中,您无法在EWS中(在exportmessage之外)访问邮件...

...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: 地址?

How would I go about doing this programatically so I can find the correct To: address?

推荐答案

这对我有用:

    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/论坛/en-au/exchangesvrdevelopment/thread/1e5bbde0-218e-466e-afcc-cb60bc2ba692

这篇关于Exchange Web服务(EWS)API“收件人"别名标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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