我正在尝试使用C#检索雅虎帐户上的邮件。我测试了OpenPop来做到这一点,我写了那个
Pop3Client objClient = new Pop3Client();
objClient.Connect("pop.mail.yahoo.com", 995, true);
objClient.Authenticate("username","pass",AuthenticationMethod.UsernameAndPassword);
int msgCount = objClient.GetMessageCount();
MessageBox.Show(msgCount.ToString());
服务器始终不接受用户凭据的问题,但我确定凭据没问题。
我用我的gmail帐户尝试了相同的代码,一切都很好,雅虎是否缺少某些东西,希望我设置它?
为了通过电子邮件程序访问雅虎邮件,您需要成为雅虎邮件Plus订阅者。
1. Sign in to Yahoo Mail.
2. Move your cursor over the gear icon (Gear Icon) and select Mail Options.
3. Select POP & Forwarding.
- The "Access your Yahoo Mail elsewhere" option displays.
4. Select the radio button next to Access Yahoo Mail via POP.
5. Click Save.
尝试以下代码:
try
{
if (pop3Client.Connected)
pop3Client.Disconnect();
pop3Client.Connect("pop.mail.yahoo.com", 995, true);
pop3Client.Authenticate("your@yahoo.com", "yourpassword");
int count = pop3Client.GetMessageCount();
}
catch (InvalidLoginException)
{
//MessageBox.Show(this, "The server did not accept the user credentials!", "POP3 Server Authentication");
}
catch (PopServerNotFoundException)
{
//MessageBox.Show(this, "The server could not be found", "POP3 Retrieval");
}
catch (PopServerLockedException)
{
//MessageBox.Show(this, "The mailbox is locked. It might be in use or under maintenance. Are you connected elsewhere?", "POP3 Account Locked");
}
catch (LoginDelayException)
{
//MessageBox.Show(this, "Login not allowed. Server enforces delay between logins. Have you connected recently?", "POP3 Account Login Delay");
}
catch (Exception e)
{
//MessageBox.Show(this, "Error occurred retrieving mail. " + e.Message, "POP3 Retrieval");
}