我正在使用EWS从Exchange 2013提供的电子邮件中读取和提取图像。使用下面的代码,当图像作为实际附件附加时效果很好。当图像作为内联附件出现时出现问题。
EWS .Hasattachments并不适用于内联附件..这似乎很愚蠢,这是没有想到的..阅读下面的文章似乎有一个解决但我只是想知道什么是最好的,最有效的检索常规&的方法内联图像附件并将其保存到目录中。
if (mail.HasAttachments && mail.Attachments[0] is FileAttachment)
{
int count = 0;
foreach (Attachment attachment in mail.Attachments)
{
if (attachment is FileAttachment && attachment.ContentType == "image/jpeg")
{
Console.WriteLine(attachment.Name);
FileAttachment fileAttachment = attachment as FileAttachment;
string imagename = s + "-" + System.DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";
/* download attachment to folder */
fileAttachment.Load(imageLocation + "\\Images\\" + imagename);
}
答案 0 :(得分:0)
看起来你在第一行中从this MSDN article获得了一些灵感。您不需要检查HasAttachments
,只需遍历mail.Attachments
自己。
foreach (var attachment in mail.Attachments.Where(a => a is FileAttachment && a.ContentType == "image/jpeg"))
{
Console.WriteLine(attachment.Name);
FileAttachment fileAttachment = attachment as FileAttachment;
string imagename = s + "-" + System.DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";
/* download attachment to folder */
fileAttachment.Load(imageLocation + "\\Images\\" + imagename);
}
我没有对上述内容进行测试,但只能对任何jpeg FileAttachment