小编jab*_*idi的帖子

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

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

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

有什么建议么?

干杯

c# smtp smtpclient smtp-auth mailkit

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

mailkit ×1

smtp ×1

smtp-auth ×1

smtpclient ×1