0

I have been trying to use the solution provided in the following link:
using c# .net librarires to check for IMAP messages from gmail servers

But I keep hitting the error:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Is there something that I am missing here. My Code:

    public List<MailMessage> ReadMail()
    {
        List<MailMessage> msgs;
        using (var ic = new AE.Net.Mail.ImapClient("imap.gmail.com", "username@gmail.com", "pass-to-gmail", ImapClient.AuthMethods.Login, 993, true))
        {
            ic.SelectMailbox("INBOX");
            msgs = new List<MailMessage>(ic.GetMessageCount());
            msgs = ic.GetMessages(0, 100, false, true).ToList();

            ic.Disconnect();
        }
        return msgs;
    }
Community
  • 1
  • 1
Amit M
  • 11
  • 1
  • 5

1 Answers1

0

Use this piece of code to connect to gmail.

ImapX.ImapClient client = null;
client = new ImapX.ImapClient("imap.gmail.com", 993, true);

if (!client.Connection())
{
    MessageBox.Show("Couldn't connect to gmail. Check your internet connection and try again");
    client = null;
    return false;
 }

 if (!client.LogIn(email, password))
 {
     MessageBox.Show("Email And/Or password incorrect");
     client = null;
     return false;
 }
Ibrahim
  • 837
  • 2
  • 13
  • 24
  • hey thanks. turns out my network was blocking the call request. When I the same code using different network, it worked. – Amit M Apr 03 '13 at 07:02
  • Hi Amit, I tried to run your same code. It fails :( Is it because of any firewall that is protecting the code from accessing the mails? Please suggest. – Sriram B Jul 22 '13 at 08:48