我正在开发一个控制台应用程序,它将监视Exchange服务器并从新电子邮件下载附件(XML文件)。我已经为此使用了EaGetmail。附件正在下载到目标文件夹,但它是空的。寻找解决方案。这是我的示例代码,任何建议请。
private static void CheckInboxforEmail()
{
// Use domainuser 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)
{
}
}
试试这个它对我有用!!!
//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);
}