2012-09-04 17 views
8

ho bisogno di ottenere e salvare gli allegati (s) da un elemento di posta, ma usando il codice seguente restituisce tutti gli allegati - che significa che restituisce anche le immagini incorporate come la firma del mittente con il logo, che è l'immagine. In che modo è possibile differenziare un allegato vero e immagini incorporate? Ho visto molto dai forum ma non mi è ancora chiaro.VSTO + differenziare allegati

public static void SaveData(MailItem currentMailItem) 
{ 
    if (currentMailItem != null) 
    {  
     if (currentMailItem.Attachments.Count > 0) 
     { 
      for (int i = 1; i <= currentMailItem.Attachments.Count; i++) 
      { 
       currentMailItem.Attachments[i].SaveAsFile(@"C:\TestFileSave\" + currentMailItem.Attachments[i].FileName); 
      } 
     } 
    } 
} 

risposta

8

È possibile verificare se un allegato è in linea o non utilizzando la seguente pseudo-code from MS Technet Forums.

if body format is plain text then 
    no attachment is inline 
else if body format is RTF then 
    if PR_ATTACH_METHOD value is 6 (ATTACH_OLE) then 
    attachment is inline 
    else 
    attachment is normal 
else if body format is HTML then 
    if PR_ATTACH_FLAGS value has the 4 bit set (ATT_MHTML_REF) then 
    attachment is inline 
    else 
    attachment is normal 

È possibile accedere alla messaggio in formato corpo utilizzando MailItem.BodyFormat e le proprietà di fissaggio MIME utilizzando Attachment.PropertyAccessor.

string PR_ATTACH_METHOD = 'http://schemas.microsoft.com/mapi/proptag/0x37050003'; 
var attachMethod = attachment.PropertyAccessor.Get(PR_ATTACH_METHOD); 

string PR_ATTACH_FLAGS = 'http://schemas.microsoft.com/mapi/proptag/0x37140003'; 
var attachFlags = attachment.PropertyAccessor.Get(PR_ATTACH_FLAGS); 
+1

grazie mille! Funziona! – Liz