我正在使用OpenPop.net尝试解析我们从给定收件箱中的所有电子邮件中的链接。我发现这个方法来获取所有的消息:OpenPop.net获取实际消息文本
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;
}
}
现在我通过每封邮件试图循环,但我似乎无法弄清楚如何做到这一点,我有这个迄今为止对我的按钮:
private void button7_Click(object sender, EventArgs e)
{
List<OpenPop.Mime.Message> allaEmail = FetchAllMessages("pop3.live.com", 995, true, "[email protected]", "xxxxx");
var message = string.Join(",", allaEmail);
MessageBox.Show(message);
}
我将如何循环通过allaEmail中的每个条目,以便我可以将其显示在MessageBox中?
哇谢谢你foens!那正是我所追求的! :)复选框提交 – user1213488
html.GetBodyAsText()提供了一个异常,表示objectreference未设置为实例。但我使用FindFirstPlainTextVersion()获取值,然后使用plainText.GetBodyAsText()知道为什么? – Antony