2

问题

如何使用 EWS(Exchange 2013,C#)查看附件属性并检索原始发件人的电子邮件地址?不是当前发件人的电子邮件地址,而是附加到此电子邮件的电子邮件的发件人。

我做了什么

许多谷歌搜索只向我展示了如何检索当前电子邮件的发件人而不是附件。我这样做是通过

//get sender of email to TR
EmailMessage mes = (EmailMessage)item;
String sender = mes.Sender.Address;

要求

想法?链接?示例代码?我现在正在寻找任何可以用来帮助我加载附件并提取发件人电子邮件地址的东西。谢谢!

4

1 回答 1

3

您想获取附加电子邮件的详细信息吗?

试试这个代码片段?假设 _ewsService 是一个正确绑定的服务客户端。

var results = _ewsService.FindItems(WellKnownFolderName.Inbox, new ItemView(100)); //fetch 100 random emails from inbox

foreach (var entry in results.Items)
{
    if (entry is EmailMessage)
    {
        var temp = EmailMessage.Bind(_service, entry.Id);

        if (entry.HasAttachments)
        {
            temp.Load(new PropertySet(EmailMessageSchema.Attachments));

            foreach (var singleItem in temp.Attachments)
            {
                if (singleItem is ItemAttachment)
                {
                    var attachedMail = singleItem as ItemAttachment;

                    attachedMail.Load();

                    Console.WriteLine(attachedMail.Item is EmailMessage);

                    var workingMessage = attachedMail.Item as EmailMessage; //this should give you from, subject, body etc etc.
                }
            }
        }
    }
}
于 2013-07-11T21:15:43.930 回答