OpenPop.net receives message text

I use OpenPop.net to try to parse our links from all emails that are in the given mailbox. I found this method to get the whole message:

public static List<OpenPop.Mime.Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password) { // The client disconnects from the server when being disposed using (Pop3Client client = new Pop3Client()) { // Connect to the server client.Connect(hostname, port, useSsl); // Authenticate ourselves towards the server client.Authenticate(username, password); // Get the number of messages in the inbox int messageCount = client.GetMessageCount(); // We want to download all messages List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount); // Messages are numbered in the interval: [1, messageCount] // Ergo: message numbers are 1-based. // Most servers give the latest message the highest number for (int i = messageCount; i > 0; i--) { allMessages.Add(client.GetMessage(i)); } client.Disconnect(); // Now return the fetched messages return allMessages; } } 

Now I'm trying to skip every message, but I can’t figure out how to do this, I still have this for my button:

  private void button7_Click(object sender, EventArgs e) { List<OpenPop.Mime.Message> allaEmail = FetchAllMessages("pop3.live.com", 995, true, "xxxxx@hotmail.com", "xxxxx"); var message = string.Join(",", allaEmail); MessageBox.Show(message); } 

How would I scroll through each entry in allaEmail so that I can display it in a MessageBox?

+8
c # email openpop
source share
2 answers

I see that you are using the fetchAllEmail example from the OpenPop homepage. A similar example showing how to get body text is also on the main page.

You can also see how emails are actually structured. An email exists for this purpose.

Having said that, I will do something similar to the code below.

 private void button7_Click(object sender, EventArgs e) { List<OpenPop.Mime.Message> allaEmail = FetchAllMessages(...); StringBuilder builder = new StringBuilder(); foreach(OpenPop.Mime.Message message in allaEmail) { OpenPop.Mime.MessagePart plainText = message.FindFirstPlainTextVersion(); if(plainText != null) { // We found some plaintext! builder.Append(plainText.GetBodyAsText()); } else { // Might include a part holding html instead OpenPop.Mime.MessagePart html = message.FindFirstHtmlVersion(); if(html != null) { // We found some html! builder.Append(html.GetBodyAsText()); } } } MessageBox.Show(builder.ToString()); } 

Hope this helps you with this. Please note that there is also online documentation for OpenPop.

+25
source share

Here is how I did it:

 string Body = msgList[0].MessagePart.MessageParts[0].GetBodyAsText(); foreach( string d in Body.Split('\n')){ Console.WriteLine(d); } 

Hope this helps.

0
source share

All Articles