使用 Mailkit:“SMTP 服务器意外断开连接。”

jab*_*idi 2 c# smtp smtpclient smtp-auth mailkit

我正在尝试使用 SendGrid 的免费 SMTP 中继从我的 ASP.NET 应用程序发送电子邮件。我可以连接到服务器,但当我尝试进行身份验证时,收到此错误:“SMTP 服务器意外断开连接。”

using (var client = new SmtpClient())
        {
            client.ServerCertificateValidationCallback =
                (sender, certificate, certChainType, errors) => true;
            client.AuthenticationMechanisms.Remove("XOAUTH2");

            // connection
            client.Connect("smtp.host", 465, true);
            client.Authenticate("UserName", "Password");//error occurs here

            client.Send(email);
            client.Disconnect(true);
        }
Run Code Online (Sandbox Code Playgroud)

再次,我可以毫无问题地连接,但是当我尝试进行身份验证时,我收到前面提到的错误......

有什么建议么?

干杯

EzL*_*zLo 9

您必须提供:

  • 用户名:是apikey(作为硬编码值“apikey”)。
  • 密码:是您从网络生成的 apikey,它是一个类似散列的大字符串。

您可以在他们的文档中找到这一点。但很难找到。