// POP3: Get all messages in server (HostPOP) and after that, delete all od messages in that server public int GetMailPOPDelete(string FolderName, string HostPOP, int PortPOP, bool SSLSupport, string MailName, string PWstring) { if (!imapConnect()) return -1; //choose current folfer if (!imapClient.SelectMailbox(FolderName)) { // if folder is not exist, create new folder imapClient.CreateMailbox(FolderName); imapClient.SelectMailbox(FolderName); } MessageSet OLdMSSet = imapClient.Search("ALL", true); MailMan subpopClient = new MailMan(); if (!subpopClient.UnlockComponent("MAIL-TEAMBEAN_4895F76A292K")) return -1; // config info of pop server subpopClient.MailHost = HostPOP; subpopClient.MailPort = PortPOP; subpopClient.PopUsername = MailName; subpopClient.PopPassword = PWstring; if (SSLSupport) subpopClient.PopSsl = true; //SSL support else subpopClient.PopSsl = false; //connect without SSL support subpopClient.ConnectTimeout = 15; // defaulf timeout = 30, so when it can't connect, it's too slow EmailBundle colecMessageInfo = subpopClient.CopyMail(); //Copy all of mail in mailbox of pop server if (colecMessageInfo == null) //connect fail, or don't have any new message { imapDisconnect(); return -1; } else { //copy new message to folder on our server for (int i = 0; i < colecMessageInfo.MessageCount; i++) { Email msif = colecMessageInfo.GetEmail(i); imapClient.AppendMail(FolderName, msif); } } subpopClient.DeleteBundle(colecMessageInfo); //delete all messages on pop server // mark new message unread // it's a little complex here, contact me if you need support imapClient.SelectMailbox(FolderName); MessageSet NewMSSet = imapClient.Search("ALL", true); for (int i = 0; i < OLdMSSet.Count; i++) NewMSSet.RemoveId(OLdMSSet.GetId(i)); imapClient.SetFlags(NewMSSet, "Seen", 0); imapDisconnect(); return colecMessageInfo.MessageCount; }
public static void ScanGmail(string[] strings, Types type) { Console.WriteLine("VER 3"); Bounce b = new Bounce(); b.UnlockComponent("DONTSTAYINBOUNCE_OS2MBg0e7GpB"); MailMan mailman = new MailMan(); mailman.UnlockComponent("DONTSTAYINMAILQ_5CHEZpZc7Gp9"); //mailman.ConnectTimeout = 5; mailman.MailPort = 995; mailman.PopSsl = true; mailman.MailHost = "pop.gmail.com"; if (type == Types.DontStayIn) { Console.WriteLine("*****@*****.**"); mailman.PopUsername = "******"; mailman.PopPassword = "******"; } else if (type == Types.Mixmag) { Console.WriteLine("*****@*****.**"); mailman.PopUsername = "******"; mailman.PopPassword = "******"; } else if (type == Types.SpamTrap) { Console.WriteLine("*****@*****.**"); mailman.PopUsername = "******"; mailman.PopPassword = "******"; } // Copy the mail into a bundle object. The mail still remains // on the POP3 server. Call TransferMail to copy and remove // mail from the POP3 server. Chilkat.EmailBundle bundle; Console.WriteLine("Getting bundle..."); List<string> emailAddresses = new List<string>(); int ignored = 0; int ignoredHard = 0; int hardBounces = 0; int exceptions = 0; int total = 0; // Loop over each email and save attachments. // Also add the email subject to a list box. do { emailAddresses = new List<string>(); ignored = 0; ignoredHard = 0; hardBounces = 0; exceptions = 0; total = 0; bundle = mailman.CopyMail(); Console.WriteLine("Got {0} messages", bundle.MessageCount.ToString()); total = bundle.MessageCount; int i; for (i = 0; i < bundle.MessageCount; i++) { Chilkat.Email email = bundle.GetEmail(i); try { Console.Write("."); if (type == Types.SpamTrap) { #region spam trap if (email.Subject == "complaint about message from 84.45.14.32") { bool isEflyer = false; bool isUpdateEmail = false; string fullBody = email.Body; string recipient = ""; string subject = ""; //Console.WriteLine(fullBody.Length > 4096 ? fullBody.Substring(0, 4096) : fullBody); //Console.ReadLine(); if (fullBody.IndexOf("From: [email protected]\r", StringComparison.OrdinalIgnoreCase) == -1) { isEflyer = true; } if (fullBody.IndexOf("Subject: DontStayIn this week", StringComparison.OrdinalIgnoreCase) > -1 || fullBody.IndexOf("Subject: Don't Stay In this week", StringComparison.OrdinalIgnoreCase) > -1) { isUpdateEmail = true; } { string firstLine = fullBody.Substring(0, fullBody.IndexOf("\r")); recipient = firstLine.Substring(firstLine.IndexOf(" ") + 1); } { string subjectAndOn = fullBody.Substring(fullBody.IndexOf("\r\nSubject: ", StringComparison.OrdinalIgnoreCase) + 11); subject = subjectAndOn.Substring(0, subjectAndOn.IndexOf("\r")); } Console.WriteLine("Email: {0}, Eflyer: {1}, UpdateEmail: {2}, Subject: {3}", recipient, isEflyer, isUpdateEmail, subject.Length > 30 ? subject.Substring(0,30) : subject); UsrSet us = new UsrSet(new Query(new Q(Usr.Columns.Email, recipient))); if (us.Count > 0) { foreach (Usr u in us) { if (isEflyer) { u.SendFlyers = false; } else if (isUpdateEmail) { u.SendSpottedEmails = false; } else { u.EmailHold = true; } u.Update(); } } } else Console.WriteLine("(not complaint email)"); #endregion } else { b.ExamineEmail(email); dealWithBounce(strings, b, "", ref hardBounces, ref ignoredHard, ref ignored); } } catch (Exception ex) { Console.WriteLine("EXCEPTION"); //Console.WriteLine(ex.Message); //throw ex; exceptions++; } //Console.WriteLine(""); //if (i < 10 || i % 10 == 0) // Console.WriteLine("Processed: " + i.ToString("#,##0") + " / " + total.ToString("#,##0") + ", bounces: " + hardBounces.ToString("#,##0") + ", ignored: " + ignored.ToString("#,##0") + ", ignoredHard: " + ignoredHard.ToString("#,##0") + ", errors: " + exceptions.ToString("#,##0")); } } while (total >= 250); }