user2033791
user2033791

Reputation: 830

Can't connect to Gmail with IMAPX using c#

I'm following an example from IMAPX but it will not connect to GMAIL. IMAP is enabled for the account and I've triple checked the username and password but it won't connect:

var server = ConfigurationManager.AppSettings["server"];
var login = Decrypt(ConfigurationManager.AppSettings["user"]);
var password = Decrypt(ConfigurationManager.AppSettings["pass"]);

//create the IMAP CLient
var client = new ImapClient(server, true);

//connect to the server
if (!client.Connect())
{
    Console.WriteLine("Error: Failed to connect");
    return;
}

//login to the server
if (!client.Login(login, password))
{
    Console.WriteLine("Error: Invalid login");
    return;
}

Anyone have any idea how to use this library to connect to gmail? I have tried variations of "use SSL" and "verify certificate", but no mater what I try the login always fails.

Upvotes: 0

Views: 1459

Answers (1)

Mad Myche
Mad Myche

Reputation: 1075

Google by default does not allow "less secure" apps from account access unless the account is setup to allow it.

References:

Upvotes: 3

Related Questions