2012-06-28 62 views
0

我使用EWS 1.2來搜索我的郵箱中有附件的電子郵件,我將EmailMessage對象綁定到EWS對象。這是工作的罰款,但沒有檢測到.msg文件(Outlook郵件文件):電子郵件消息時,EWS無法檢測到.MSG文件

ItemView mailview = new ItemView (12); 
FindItemsResults<Item> resultmail; 

resultmail = Service.FindItems(WellKnownFolderName.Inbox, mailview); 
foreach (Item item in resultmail.Items) 
{     
    EmailMessage email = EmailMessage.Bind(Service, item.Id, 
     new PropertySet(BasePropertySet.FirstClassProperties, 
         ItemSchema.Attachments)); 

    if (email.HasAttachments) 
    { 
     foreach (var attachment in email.Attachments) 
     { 
      if (attachment is FileAttachment) 
      { 
       Console.WriteLine("email has : " + email.Attachments.Count 
           + "attachement(s)" + "\n"); 
       Console.WriteLine("attachment name:" + attachment.Name); 
      } 
     } 
    } 
} 

回答

1

如果郵件被附加在郵件中,它不是一個FileAttachment的,它是一個itemattachment。所以你應該像這樣擴展你的代碼:

... 
if (attachment is FileAttachment) 
{ 
    Console.WriteLine("email has : " + email.Attachments.Count + "attachement(s)" + "\n"); 
    Console.WriteLine("attachment name:" + attachment.Name); 
} 
else if (attachment is ItemAttachment) 
{ 
    ItemAttachment itematt = (ItemAttachment) attachment; 
    //with itematt.Item you can access the properties of the attachment. 
} 
+0

謝謝你的工作 – ssq

相關問題