2014-09-25 59 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屬性是假返回內聯附件,即使附件集合已填充。這令人困惑。

相關問題