2014-09-25 156 views
0

我在C#中使用EWS查询邮箱中的电子邮件。我能够获得电子邮件正文消息。我想知道如何获取电子邮件中嵌入的图像。如何使用EWS检索嵌入在电子邮件正文中的图像

以下是电子邮件正文的示例。我想下载图片“cid:[email protected]”,我该怎么做?

<body lang="EN-US" link="#0563C1" vlink="#954F72"> 
<div class="WordSection1"> 
<p class="MsoNormal">Solid wood dining table with 6 chairs (2 captain chairs, 4 armless).&nbsp; Great condition.<o:p></o:p></p> 
<p class="MsoNormal"><o:p>&nbsp;</o:p></p> 
<p class="MsoNormal"><o:p>&nbsp;</o:p></p> 
<p class="MsoNormal"><img width="469" height="287" id="Picture_x0020_1" src="cid:[email protected]"> 
<o:p></o:p></p> 
<p class="MsoNormal">&nbsp;<img width="212" height="313" id="Picture_x0020_2" src="cid:[email protected]">&nbsp;&nbsp;&nbsp;&nbsp;<img width="281" height="469" id="Picture_x0020_3" src="cid:[email protected]"><o:p> 
</o:p></p> 
</div> 
</body> 

回答

3

图像应该位于Attachments集合中,因此您应该只需枚举附件集合即可找到匹配的Cid并下载它。该附件集合不会FindItems操作,所以你需要确保你使用的消息getItem操作,让那些细节,例如

 ItemView view = new ItemView(100); 
     view.PropertySet = new PropertySet(PropertySet.IdOnly); 
     PropertySet PropSet = new PropertySet(); 
     PropSet.Add(ItemSchema.HasAttachments); 
     PropSet.Add(ItemSchema.Body); 
     PropSet.Add(ItemSchema.DisplayTo); 
     PropSet.Add(ItemSchema.IsDraft); 
     PropSet.Add(ItemSchema.DateTimeCreated); 
     PropSet.Add(ItemSchema.DateTimeReceived); 
     PropSet.Add(ItemSchema.Attachments); 
     FindItemsResults<Item> findResults; 
     do 
     { 
      findResults = service.FindItems(WellKnownFolderName.Inbox, view); 
      if (findResults.Items.Count > 0) 
      { 
       service.LoadPropertiesForItems(findResults.Items, PropSet); 
       foreach (var item in findResults.Items) 
       { 
        foreach (Attachment Attach in item.Attachments) { 
         if (Attach.IsInline) { 

          Console.WriteLine(Attach.ContentId); 
          if(Attach.ContentId == "[email protected]"){ 
           ((FileAttachment)Attach).Load(@"c:\temp\downloadto.png"); 
          } 
         } 
        }      
       } 
      } 
      view.Offset += findResults.Items.Count; 
     } while (findResults.MoreAvailable); 

干杯 格伦

0

的HasAttachments属性是假返回内联附件,即使附件集合已填充。这令人困惑。

相关问题