public void FetchMessages(NameValueCollection param) { Pop3 client = new Pop3(); bool connected = false; try { string outdir = RequireParam("outdir", param); if (!Directory.Exists(outdir)) Directory.CreateDirectory(outdir); string server = RequireParam("server", param); int port = Convert.ToInt32(RequireParam("port", param)); string ssl = param["ssl"]; if (ssl.Length == 0) ssl = port == 995 ? "1" : "0"; TlsParameters par = new TlsParameters(); par.CommonName = server; par.CertificateVerifier = CertificateVerifier.AcceptAll; Pop3Security sec = (Pop3Security)Enum.Parse(typeof(Pop3Security), RequireParam("security", param)); log.Info("Connecting to {0}:{1}. SSL: {2}", server, port, ssl); string sess = client.Connect(server, port, par, sec); connected = true; log.Info("Connected: {0}", sess); Pop3Authentication auth = (Pop3Authentication)Enum.Parse(typeof(Pop3Authentication), RequireParam("auth", param)); log.Info("Logging in: {0}", RequireParam("user", param)); client.Login(RequireParam("user", param), RequireParam("pwd", param), auth); log.Info("Logged in."); Pop3MessageCollection messages = client.GetMessageList(); log.Info("There are {0} messages", messages.Count); int maxcount = Convert.ToInt32(RequireParam("maxcount", param)); if (maxcount <= 0 || maxcount > messages.Count) maxcount = messages.Count; for (int i = 0; i < maxcount; i++) { Pop3MessageInfo mi = messages[i]; log.Info("Downloading message {0}", mi.SequenceNumber); MailMessage mm = client.GetMailMessage(mi.SequenceNumber); log.Info("Message from: {0}, to: {1}, subject: {2}", mm.From, mm.To, mm.Subject); string g = Guid.NewGuid().ToString(); string file = Path.Combine(outdir, g + ".eml"); log.Info("Saving message to {0}", file); mm.Save(file); client.Delete(mi.SequenceNumber); } bool rollback = !"0".Equals(RequireParam("noremove", param)); client.Disconnect(rollback); } catch (Exception ex) { if (connected) client.Disconnect(true); throw; } }
internal int Pop3Check() { try { var pop3Settings = new Pop3Settings(); var obj = new Pop3(); obj.Connect(pop3Settings.Host, pop3Settings.Username, pop3Settings.Password, pop3Settings.Port); string KeyWord = Helpers.Xml.AppConfigQuery("jaNET/System/Comm/MailKeyword").Item(0).InnerText; foreach (Pop3Message msg in obj.List()) { Pop3Message msg2 = obj.Retrieve(msg); /*Console.WriteLine("Message {0}: {1}", * msg2.number, msg2.message);*/ if (msg2.Message.Contains("<" + KeyWord + ">")) { //If a command found to mail subject Match Command = Regex.Match(msg2.Message.Replace("\r\n", " "), @"(<" + KeyWord + ">)(.*?)(?=</" + KeyWord + ">)"); Command.ToString().ToLower().Replace("<" + KeyWord + ">", string.Empty).Parse(); obj.Delete(msg2); } else { //For Future Use /*Match From = Regex.Match(msg2.message, @"(?<=From: )(.*?)(?= <)"); * Match Subject = Regex.Match(msg2.message, @"(?<=Subject: )(.*?)(?=\\r\\nDate: )"); //(?<=Subject:</B> )(.*?)(?=</)"); * MailList.Add("From " + From.ToString() + ", Subject " + Subject.ToString());*/ //From pattern (?<=From: \\\")(.*?)(?=\\\") //Subject pattern (?<=Subject: )(.*?)(?=\\r) } } obj.Disconnect(); return(obj.List().Count); } catch { return(0); } }
private void CheckEmail(object sender, System.Timers.ElapsedEventArgs args) { try { m_pop3 = new Pop3(); m_pop3.Connect(m_strServer, m_strLogin, m_strPassword); ArrayList list = m_pop3.List(); foreach (Pop3Message msg in list) { Pop3Message msg2 = m_pop3.Retrieve(msg); m_pop3.Delete(msg); _OnMessageReceived(msg2.From, msg2.Subject, false); } m_pop3.Disconnect(); } catch (Pop3Exception e) { _OnError(this, e.Message); return; } }
internal int Pop3Check() { try { var pop3Settings = new Pop3Settings(); var obj = new Pop3(); obj.Connect(pop3Settings.Host, pop3Settings.Username, pop3Settings.Password, pop3Settings.Port); string KeyWord = Helpers.Xml.AppConfigQuery("jaNET/System/Comm/MailKeyword").Item(0).InnerText; foreach (Pop3Message msg in obj.List()) { Pop3Message msg2 = obj.Retrieve(msg); /*Console.WriteLine("Message {0}: {1}", msg2.number, msg2.message);*/ if (msg2.Message.Contains("<" + KeyWord + ">")) { //If a command found to mail subject Match Command = Regex.Match(msg2.Message.Replace("\r\n", " "), @"(<" + KeyWord + ">)(.*?)(?=</" + KeyWord + ">)"); Command.ToString().ToLower().Replace("<" + KeyWord + ">", string.Empty).Parse(); obj.Delete(msg2); } else { //For Future Use /*Match From = Regex.Match(msg2.message, @"(?<=From: )(.*?)(?= <)"); Match Subject = Regex.Match(msg2.message, @"(?<=Subject: )(.*?)(?=\\r\\nDate: )"); //(?<=Subject:</B> )(.*?)(?=</)"); MailList.Add("From " + From.ToString() + ", Subject " + Subject.ToString());*/ //From pattern (?<=From: \\\")(.*?)(?=\\\") //Subject pattern (?<=Subject: )(.*?)(?=\\r) } } obj.Disconnect(); return obj.List().Count; } catch { return 0; } }