【发布时间】:2018-02-15 12:42:51
【问题描述】:
我正在使用 EWS 从 Exchange 2013 提供的电子邮件中读取和提取图像。使用下面的代码,当图像作为实际附件附加时效果很好。当图像作为内联附件出现时,就会出现问题。
EWS .Hasattachments 不会为内联附件返回 true。这似乎很愚蠢。阅读下面的文章似乎可以解决问题,但我只是想知道什么是最好的、最有效的检索常规和内联图像附件并将它们保存到目录的方法。
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);
}
【问题讨论】:
-
我将代码更改为以下,但每次在 Error itemNot Found 的 .load 语句上都会抛出一个错误。
-
Console.WriteLine(attachment.Name);字符串 sID = 附件.ContentId; sType = sType.Replace("image/", "");字符串 sFilename = 附件。名称;字符串 sPathPlusFilename = Directory.GetCurrentDirectory() + "\\" + sFilename; ((FileAttachment)attachment).Load(sFilename);