private void _bCountMessage_Click(object sender, EventArgs e) { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}",_tbPop3Server.Text)); // Connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); //Display Msg Count this.AddLogEntry(string.Format("Message Count: {0}", pop.MessageCount.ToString())); } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
private void _bDomainKey_Click(object sender, EventArgs e) { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // Connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); if (pop.MessageCount > 0) { //Retrive a message at a particulat index ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(1); if (message.HasDomainKeySignature) { bool signatureValid = message.Signatures.DomainKeys.Verify(); if (signatureValid) { this.AddLogEntry("The domain key signature is valid."); } else { this.AddLogEntry("The domain key signature is invalid."); } } else { this.AddLogEntry("The message hasn't domain key signature."); } } else { this.AddLogEntry("There is no messages in the pop3 account."); } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
static void Main(string[] args) { System.Console.WriteLine("Start work"); string sHostPop = "pop.googlemail.com"; string sHostImap = "imap.googlemail.com"; int nPort = 995; string sUserName = "******"; string sPasword = "theSimpsons"; try { string sEml = @"E:\ut8_encripted_teamlab.eml"; ActiveUp.Net.Mail.Message m = ActiveUp.Net.Mail.Parser.ParseMessageFromFile(sEml); var header = ActiveUp.Net.Mail.Parser.ParseHeader(sEml); Pop3Client pop = new Pop3Client(); // Connect to the pop3 client pop.ConnectSsl(sHostPop, nPort, "recent:" + sUserName, sPasword); if (pop.MessageCount > 0) { ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(4); string sHtml = message.BodyHtml.Text; } else System.Console.WriteLine("No letters!"); pop.Disconnect(); Imap4Client imap = new Imap4Client(); imap.ConnectSsl(sHostImap, 993); imap.Login(sUserName, sPasword); Mailbox inbox = imap.SelectMailbox("inbox"); if (inbox.MessageCount > 0) { ActiveUp.Net.Mail.Message message = inbox.Fetch.MessageObject(6); string sHtml = message.BodyHtml.Text; } imap.Disconnect(); } catch (Exception ex) { System.Console.Write("\r\n" + ex); } System.Console.WriteLine("Stop work"); System.Console.ReadKey(); }
private void _bRetrieveSpecificMessage_Click(object sender, EventArgs e) { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { _lvMessages.Items.Clear(); this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // Connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); if (pop.MessageCount > 0) { //Retrive a messaheader at a particulat index (index 1 in this sample) for (int i = 1 ; i < pop.MessageCount + 1; i++) { ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(i); ListViewItem lvi = new ListViewItem(); lvi.Text = i.ToString("0000"); lvi.SubItems.AddRange(new string[] { message.Subject }); lvi.Tag = message; _lvMessages.Items.Add(lvi); this.AddLogEntry(string.Format("{3} Subject: {0} From :{1} Message Body {2}" , message.Subject, message.From.Email, message.BodyText,i.ToString("0000"))); } } else { this.AddLogEntry("There is no message in this pop3 account"); } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
private void _bCheckBounce_Click(object sender, EventArgs e) { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // We connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); if (pop.MessageCount > 0) { // We retrive a message at a particular index (index 1 in this sample) ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(1); BounceResult br = message.GetBounceStatus(); if (br.Level == 3) { this.AddLogEntry(string.Format("Message sent to {0} is bounced", br.Email)); } else { this.AddLogEntry(string.Format("Message sent to {0} is not bounced", br.Email)); } } else { this.AddLogEntry("There is no message in this pop3 account"); } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
private void _bFilterEmails_Click(object sender, EventArgs e) { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // Connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); AddressCollection ac; HeaderCollection hc = new HeaderCollection(); //Retrive a message headers for (int n = 1; n < pop.MessageCount + 1; n++) { Header h = pop.RetrieveHeaderObject(n); ac = new AddressCollection(); ac.Add(h.From); ac = Validator.Filter(ac); //If address is not filtered if (ac.Count > 0) { hc.Add(h); } } this.AddLogEntry(string.Format(" {0} messages passed the filter", hc.Count.ToString())); } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
private void btnClick_Click(object sender, EventArgs e) { ToggleMyStatus(this);//Enable try { Pop3Client client = new Pop3Client(); if (chkAPOP.Checked) { client.APOPConnect(txtHost.Text, txtUser.Text, txtPassword.Text); } else client.Connect(txtHost.Text, txtUser.Text, txtPassword.Text); if (client.MessageCount == 0) { client.Disconnect(); Sleep(); MessageBox.Show("You do not have any new messages"); } else { //Load up, POP3Result. //Pass up Pop3Client, for further operations Pop3Result result = new Pop3Result(); result.Pop = client; result.ShowDialog(); client.Disconnect(); Sleep(); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } ToggleMyStatus(this);//Disable }
private void _bRetrieveMessage_Click(object sender, EventArgs e) { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // We connect to the pop3 client pop.Connect(_tbPop3Server.Text); // We authenticate securly pop.Authenticate(_tbUserName.Text, _tbPassword.Text, SaslMechanism.CramMd5); if (pop.MessageCount > 0) { //Retrive a message at a particulat index (index 1 in this sample) ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(1); this.AddLogEntry(string.Format("Subject: {0} From :{1} Message Body {2}" , message.Subject, message.From.Email, message.BodyText)); } else { this.AddLogEntry("There is no message in this pop3 account"); } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
private void _bCountMessage_Click(object sender, EventArgs e) { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // Connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); //Retrive the header of the messag at position 1 if (pop.MessageCount > 0) { Header msgHeader = pop.RetrieveHeaderObject(1); //Display the header for the first message this.AddLogEntry(string.Format("Subject: {0} From :{1} Date Sent {2}" , msgHeader.Subject, msgHeader.From.Email, msgHeader.DateString)); } else { this.AddLogEntry("There is no message in this pop3 account"); } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
private void _bRetrieveMessageList_Click(object sender, EventArgs e) { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // Connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); this.AddLogEntry("Retrieve message list"); MessageCollection mc = new MessageCollection(); for (int n = 1; n < pop.MessageCount + 1; n++) { Message newMessage = pop.RetrieveMessageObject(n); mc.Add(newMessage); this.AddLogEntry(string.Format("Message ({0}) : {1}",n.ToString(),newMessage.Subject)); } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
private void _bRetrieveMessageAsync_Click(object sender, EventArgs e) { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // Connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); if (pop.MessageCount > 0) { //Retrive the message at a particulat index pop.MessageRetrieved += new MessageRetrievedEventHandler(MessageRetrived); pop.BeginRetrieveMessage(1, null); } else { this.AddLogEntry("There is no message in this pop3 account"); } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
private void _bCheckMessage_Click(object sender, EventArgs e) { // We instantiate the pop3 client Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // We connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); if (pop.MessageCount > 0) { // We retrive a message at a particulat index ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(1); bool blackList = false; // We verify if the message is from black listed server foreach (System.Windows.Forms.ListViewItem lvi in _lvDefinedBlackList.Items) { if (message.From.Email.EndsWith(lvi.Text)) { this.AddLogEntry(string.Format("Messages from {0} are not allowed", lvi.Text)); blackList = true; } else { this.AddLogEntry(string.Format("Messages from {0} are allowed", lvi.Text)); } if (blackList) break; } if (!blackList) { foreach (string blackServer in _lvBlackListServers.Items) { if (message.From.Email.EndsWith(blackServer)) { this.AddLogEntry(string.Format("Messages from {0} are not allowed", blackServer)); blackList = true; } else { this.AddLogEntry(string.Format("Messages from {0} are allowed", blackServer)); } if (blackList) break; } } } else { this.AddLogEntry("There is no messages in the pop3 account."); } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
private void _bRetriveToFile_Click(object sender, EventArgs e) { if (_tbMessageFilename.Text == string.Empty) { this.AddLogEntry("You have to set a message filename."); } else { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // Connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); if (pop.MessageCount > 0) { // Store the message in the specified filename. pop.StoreMessage(1, false, _tbMessageFilename.Text); this.AddLogEntry("Message saved successfully."); } else { this.AddLogEntry("There is no message in this pop3 account"); } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } } }
private void _bSaveAttachment_Click(object sender, EventArgs e) { if (_tbAttachmentDirectory.Text == string.Empty) { this.AddLogEntry("You have to set a directory to store the attachments."); } else { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // Connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); if (pop.MessageCount > 0) { ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(1); if (message.Attachments.Count > 0) { // Save the first attachment to the specified directory. message.Attachments[0].StoreToFile(_fbdSaveDirectory.SelectedPath + message.Attachments[0].HeaderFields["FileName"]); this.AddLogEntry(string.Format("Attachments '{0}' saved successfully.", message.Attachments[0].HeaderFields["FileName"])); } else { this.AddLogEntry("There is no attachments in the message."); } } else { this.AddLogEntry("There is no message in this pop3 account"); } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } } }
private void btnReceive_Click(object sender, EventArgs e) { this.listBox1.Items.Clear(); // We instantiate the pop3 client. Pop3Client pop3Client = new Pop3Client(); string server = this.txtPopServer.Text; string username = txtEmail.Text; string password = txtPassword.Text; int popPort = Convert.ToInt32(txtPopPort.Text); try { // pop3Client.APOPConnect(server, popPort, username, password); pop3Client.Connect(server, popPort, username, password); // pop3Client.Authenticate(username, password, SaslMechanism.CramMd5); int count = pop3Client.MessageCount; this.AddLogEntry(string.Format("共收到{0}封 :", count)); MessageCollection mc = new MessageCollection(); //ActiveUp.Net.Mail.Message newMessage = pop.RetrieveMessageObject(count); //mc.Add(newMessage); // this.AddLogEntry(string.Format("Message ({0}) : {1}", count.ToString(), newMessage.Subject)); //for (int n = count; n >= 1; n--) //{ // var msg = pop.RetrieveMessageObject(n); // this.AddLogEntry(string.Format("{0}-({1}) : {2}", n.ToString(), msg.Date.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"), msg.Subject)); //} string str = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); DateTime d; DateTime.TryParse(str, out d); var date = DateTime.Now.AddDays(-6); while (count > 0) { var msg = pop3Client.RetrieveMessageObject(count); if (msg.Date.ToLocalTime() < date) break; var subject = msg.Subject; if (subject.Contains("问题回复-【") && subject.Contains("【") && subject.Contains("】")) { var index = subject.IndexOf("【") + 1; var issueNo = subject.Substring(index, subject.IndexOf("】") - index); } this.AddLogEntry(string.Format("{0}-({1}) : {2}", count.ToString(), msg.Date.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"), msg.Subject)); count--; } } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop3Client.IsConnected) { pop3Client.Disconnect(); } } }