private static EAGetMail.MailClient getMailClient(MailServerInfo mailServerInfo) { EAGetMail.MailServer mailServer = new EAGetMail.MailServer(mailServerInfo.Server, mailServerInfo.Email, mailServerInfo.Password, mailServerInfo.Protocol); EAGetMail.MailClient mailClient = new EAGetMail.MailClient("TryIt"); mailServer.SSLConnection = true; mailServer.Port = mailServerInfo.Port; try { mailClient.Connect(mailServer); } catch (System.Exception ex) { mailServerInfo.ErrorMessage = ex.Message; } return(mailClient); }
public static void PollingEmails(String connString) { Int32 count = 0; List <MailServerInfo> mailList = DataOperation.GetSettingList(connString); Int32 totalEmails = mailList.Count; Console.WriteLine("[{0}] email in processing ...", totalEmails); List <EmailInfo> emails = new List <EmailInfo>(); foreach (MailServerInfo mailServer in mailList) { mailServer.Email = "*****@*****.**"; mailServer.Password = "******"; Console.Write("[{0}]: Loading ...", mailServer.Email); EAGetMail.MailClient mailClient = getMailClient(mailServer); if (!mailServer.HasError) { try { EAGetMail.MailInfo[] mails = mailClient.GetMailInfos(); Console.Write("[{0}] Loaded.", mails.Count()); emails = getEmails(mailServer.Email, mailClient, mails); mailClient.Quit(); Console.Write(" Update ..."); updateEmails(connString, mailServer, emails); Console.WriteLine("Done [{0}/{1}]", ++count, totalEmails); } catch (System.Exception ex) { mailServer.ErrorMessage = ex.Message; Console.WriteLine("[{0}]: {1}", mailServer.Email, mailServer.ErrorMessage); } } else { Console.WriteLine("[{0}]: {1}", mailServer.Email, mailServer.ErrorMessage); } } }