0 votes

Limilabs.Client.ServerException: 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 74.125.68.109:143 ---> System.Net.Sockets.SocketException: 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 74.125.68.109:143
at System.Net.Sockets.Socket.Connect(IPAddress[] addresses, Int32 port)
at System.Net.Sockets.Socket.Connect(String host, Int32 port)
at Limilabs.Client.ClientBase.Connect(String host, Int32 port, Boolean useSSL)
--- End of inner exception stack trace ---
at Limilabs.Client.ClientBase.Connect(String host, Int32 port, Boolean useSSL)
at Limilabs.Client.ClientBase.Connect(String host, Int32 port)
at Limilabs.Client.IMAP.Imap.Connect(String host)
at Service.inbox(String userID, String Pwd) in e:\ravindra\programs\WebService1\AppCode\Service.cs:line 59

by
edited by

1 Answer

0 votes
 
Best answer

Gmail requires SSL, it doesn't allow unencrypted IMAP connections (port 143).
You must use Imap.ConnectSSL method. It encrypts the connections (it uses port 993):

using(Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLogin("pat@gmail.com", "password");

    imap.SelectInbox();

    List<long> uids = imap.Search(Flag.Unseen);
    foreach (long uid in uids)
    {
        var eml = imap.GetMessageByUID(uid);
        IMail email = new MailBuilder().CreateFromEml(eml);

        string subject = email.Subject;
        string text = email.Text;
    }
    imap.Close();
}

Also remember to enable IMAP access in Gmail settings.

by (301k points)
selected by
...