2014-12-05 46 views
0

我正在開發一個控制檯應用程序,它將監視Exchange服務器並從新電子郵件下載附件(XML文件)。我爲此使用了EaGetmail。 附件正在下載到目標文件夾,但它是空的。尋找解決方案。 這是我的示例代碼,任何建議請。EWS使用EaGetmail下載的Xml附件爲空

private static void CheckInboxforEmail() 
     { 
      // Use domain\user as the user name 
      MailServer oServer = new MailServer("MailID", "domain","Pwd",ServerProtocol.ExchangeEWS); 
      MailClient oClient = new MailClient("TryIt"); 

      oServer.SSLConnection = true; 
      try 
      { 
       oClient.Connect(oServer); 
       MailInfo[] infos = oClient.GetMailInfos(); 
       for (int i = 0; i < infos.Length; i++) 
       { 
        MailInfo info = infos[i]; 
        // Receive email from Exchange server 
        Mail oMail = oClient.GetMail(info);    

        //SaveAttachments 

        foreach (EAGetMail.Attachment Att in oMail.Attachments) 
        { 
         string AttName = String.Format("{0}\\{1}", WIPFolder,Att.Name); 
         oMail.SaveAs(AttName, true); 
        } 
        // Delete email from EWS server. 
         oClient.Delete(info); 
       } 
       // Quit from Exchange server. 
       oClient.Quit(); 
      } 
      catch (Exception ep) 
      { 


      } 

     } 

回答

0

試試這個它爲我工作!!!!

   //Get Attachments 
       Attachment[] atts = oMail.Attachments; 
       int count = atts.Length; 

       //Store Attachments 
       for (int ai = 0; ai < count; ai++) 
       { 
        Attachment att = atts[ai]; 
        string attname = String.Format("{0}\\{1}", mailbox, att.Name); 
        att.SaveAs(attname, true); 
       }