使用EaGetmail,EWS下载的Xml附件为空

时间:2014-12-05 02:23:57

标签: c# xml exchangewebservices

我正在开发一个控制台应用程序,它将监视Exchange服务器并从新电子邮件下载附件(XML文件)。我已经使用过EaGetmail了。 附件正在下载到目标文件夹,但它是空的。寻找解决方案。 这是我的示例代码,任何建议请

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)
            {


            }

        }

1 个答案:

答案 0 :(得分: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);
                }