我正在尝试使用 OpenPop.dll 从 C# 中的 gmail 读取电子邮件正文。我已经尝试过 gmail api,但我永远无法让它工作,所以我尝试了这个。无论如何,这是我的代码和我得到的错误。
using (Pop3Client client = new Pop3Client())
{
client.Connect("pop.gmail.com", 995, true);
client.Authenticate("signalxxxxxx@gmail.com", "xxxxxxxx", AuthenticationMethod.UsernameAndPassword);
int messageCount = client.GetMessageCount();
List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount);
for (int d = messageCount; d > 0; d--)
{
allMessages.Add(client.GetMessage(i));
}
allMessages.Add 部分给出的错误。(运行)
An unhandled exception of type 'OpenPop.Pop3.Exceptions.InvalidUseException' occurred in OpenPop.dll
Additional information: The messageNumber argument cannot have a value of zero or less. Valid messageNumber is in the range [1, messageCount]