0
MailRepository rep = new MailRepository("imap.mail.yahoo.com", 993, true, @"xxxxx@yahoo.com", "*******");
foreach (Message email in rep.GetUnreadMails("Inbox"))
{
    //Console.WriteLine(string.Format("<p>{0}: {1}</p><p>{2}</p>", email.From, email.Subject, email.BodyHtml.Text));
    Console.WriteLine(email.From);
    Console.WriteLine(email.Subject);
    Console.WriteLine(email.BodyHtml.Text);
    if (email.Attachments.Count > 0)
    {
        foreach (MimePart attachment in email.Attachments)
        {
            Console.WriteLine(string.Format("<p>Attachment: {0} {1}</p>", attachment.ContentName, attachment.ContentType.MimeType));
        }
    }
}

Above is my code, which is used to read mail content. It's working fine when i tryed for gmail port, but while going for yahoo or some other. It's not allowing me to read the mail throwing exception. Is there any other source . Please guide me

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
Ilaya Bharathi
  • 93
  • 1
  • 14

1 Answers1

0

First, check your credentials are correct.

Second, put a try catch in the constructor to see if you can get more info about the unhandled exception:

public MailRepository(string mailServer, int port, bool ssl, string login, string password)
{
  try {
    if (ssl) {
      Client.ConnectSsl(mailServer, port);
    }
    else {
      Client.Connect(mailServer, port);
    }
  Client.Login(login, password);
  }
  catch(Exception ex)
  {
     //Check the exception details here
  }
}

Third, the origin of the MailRepository class appears to be from here that uses the Imap4Client implementation which others have complained doesn't work with Yahoo: Connecting to yahoo email with IMAP4 MailSystem.NET

The accepted answer recommends using ImapX 2 - crossplatform IMAP library for .NET to handle GMail, Yahoo, etc.

Community
  • 1
  • 1
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321