使用C#检索Yahoo电子邮件详细信息

时间:2012-06-28 11:09:00

标签: c# pop3

我正在尝试使用C#在我的Yahoo帐户上检索邮件。我测试了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帐户使用相同的代码,并且一切顺利,雅虎是否希望我设置它?

2 个答案:

答案 0 :(得分:1)

要通过电子邮件程序访问Yahoo邮件,您需要成为Yahoo Mail 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.

答案 1 :(得分:0)

请尝试以下代码:

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");
}