c# - 使用 Mailkit : "The SMTP server has unexpectedly disconnected."

标签 c# smtp smtpclient mailkit smtp-auth

我正在尝试使用来自 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);
        }

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

有什么建议吗?

干杯

最佳答案

你必须提供:

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

你可以在他们的 docs 上找到这个.但是很难找到。

关于c# - 使用 Mailkit : "The SMTP server has unexpectedly disconnected.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57676716/

相关文章:

SMTP:\r\n\r(没有第二个\n)作为双换行符

c# - 发送 2000 封电子邮件

c# - 使用 SmtpClient 发送邮件时图像中断

c# - 如何实现 IComparable 接口(interface)?

c# - 在线程 C# 中抛出异常

c# - 事件不断引发,减慢代码速度。如何用线程处理它?

c# - Storyboard找不到 ControlTemplate 元素

email - Outlook 邮箱 SMTPDataError 550 传递结果横幅

python - 在Python中提取电子邮件正文

asp.net - 从 web.config 膨胀时,SmtpClient 不会进行身份验证