我想从我的gmail帐户阅读电子邮件。我用的是"OpenPop"。Pop3"从我的gmail帐户中读取电子邮件,我使用下面的代码:-
using OpenPop.Pop3;
public DataTable ReadEmailsFromId()
{
DataTable table = new DataTable();
try
{
using (Pop3Client client = new Pop3Client())
{
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;
}
但是它在抓取2016年3月4日之前的邮件,而不是抓取新的/最新的邮件。"OpenPop"有什么限制吗?还是我错过了什么?
要获得新的电子邮件,只需在用户名之前输入关键字"recent:",然后它将给出最近30天内收到的电子邮件。
using OpenPop.Pop3;
public DataTable ReadEmailsFromId()
{
DataTable table = new DataTable();
try
{
using (Pop3Client client = new Pop3Client())
{
client.Connect("pop.gmail.com", 995, true); //For SSL
client.Authenticate("recent: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通过POP3有一些怪癖。试试这些链接,看看是否有帮助。
使用OpenPop从邮件服务器获取最新邮件
当它被编程地用作POP3服务器时,Gmail表现出哪些非标准行为特征?