我想从我的雅虎邮箱帐户阅读电子邮件。我用的是"OpenPop"。Pop3"从我的雅虎邮箱帐户阅读电子邮件,我使用下面的代码:-
using OpenPop.Pop3;
public DataTable ReadEmailsFromId()
{
DataTable table = new DataTable();
try
{
using (Pop3Client client = new Pop3Client())
{
client.Connect("pop.mail.yahoo.com", 995, true); //For SSL
client.Authenticate("Username", "Password", AuthenticationMethod.UsernameAndPassword);
int messageCount = client.GetMessageCount();
for (int i = messageCount; i > 0; i--)
{
table.Rows.Add(client.GetMessage(i).Headers.Subject, client.GetMessage(i).Headers.DateSent);
string msdId = client.GetMessage(i).Headers.MessageId;
OpenPop.Mime.Message msg = client.GetMessage(i);
OpenPop.Mime.MessagePart plainTextPart = msg.FindFirstPlainTextVersion();
string message = plainTextPart.GetBodyAsText();
}
}
}
return table;
}
相同的代码能够访问其他邮件电子邮件,如gmail,outlook,但在与雅虎邮件电子邮件工作时,我能够获得主题,日期,但当来到消息部分,即:
OpenPop.Mime.Message msg = client.GetMessage(i);
OpenPop.Mime.MessagePart plainTextPart = msg.FindFirstPlainTextVersion();
给出错误"用于检索响应的流已关闭"。
这是"StackTrace":
at OpenPop.Pop3.Pop3Client.IsOkResponse(String response)
at OpenPop.Pop3.Pop3Client.SendCommand(String command)
at OpenPop.Pop3.Pop3Client.Disconnect()
at OpenPop.Pop3.Pop3Client.Dispose(Boolean disposing)
at OpenPop.Pop3.Disposable.Dispose()
请让我知道,如果我错过了什么或做错了什么。此外,我已经使雅虎邮件的电子邮件访问任何地方使用POP
首先,根据您的代码片段,您将每条消息下载4次。那将会超级慢。
至于你为什么会得到错误,我不知道。我没有得到一个错误使用MailKit:
using MimeKit;
using MailKit;
using MailKit.Net.Pop3;
public DataTable ReadEmailsFromId()
{
DataTable table = new DataTable();
try
{
using (Pop3Client client = new Pop3Client())
{
client.Connect("pop.mail.yahoo.com", 995, true); //For SSL
client.Authenticate("Username", "Password");
for (int i = client.Count - 1; i >= 0; i--)
{
var msg = client.GetMessage (i);
table.Rows.Add(msg.Subject, msg.Date);
string msdId = msg.MessageId;
string message = msg.TextBody;
}
}
}
return table;
}