无法使用 c# 使用 IMAPX 连接到 Gmail

Can't connect to Gmail with IMAPX using c#

我正在按照来自 IMAPX 的示例进行操作,但它无法连接到 GMAIL。 该帐户已启用 IMAP,我已三次检查用户名和密码,但无法连接:

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

有人知道如何使用这个库连接到 gmail 吗?我尝试了 "use SSL" 和 "verify certificate" 的变体,但无论我尝试什么,登录总是失败。

Google 默认情况下不允许 "less secure" 帐户访问应用程序,除非帐户设置为允许它。

参考文献: