问题
如何使用EWS(Exchange 2013,C#)查看附件属性并检索原始发件人的电子邮件地址?不是当前发件人的电子邮件地址,而是附加到此电子邮件的电子邮件的发件人。
我做了什么
很多谷歌搜索只向我展示了如何检索当前电子邮件的发件人而不是附件。我这样做是
//get sender of email to TR
EmailMessage mes = (EmailMessage)item;
String sender = mes.Sender.Address;
请求
思考?链接?示例代码?我正在寻找任何可以帮助我加载附件并提取发件人电子邮件地址的内容。谢谢!
答案 0 :(得分: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.
}
}
}
}
}