c# - 系统.Net.Mail.SmtpException : The SMTP server requires a secure connection or the client was not authenticated

标签 c# smtp smtpclient

我正在尝试从 C# 应用程序发送包含我网站地址的电子邮件。
直到最近,这几个月都运行良好。 (也许我的供应商改变了一些东西或其他人改变了设置)

代码如下:

  private void sendEmail(Email invite) {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient(smtpServerName);
            mail.From = new MailAddress(emailUsername);

            mail.To.Add(invite.RecipientEmail);
            mail.Subject = invite.MessageSubject;
            mail.Body = invite.MessageBody;

            SmtpServer.UseDefaultCredentials = false;
            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);
//          SmtpServer.EnableSsl = true;
            SmtpServer.Send(mail);
        }  

这是错误:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required.

查看其他问题,我尝试了他们的建议,使 SmtpServer.EnableSsl = true。这根本不起作用。它给出了以下内容:

System.Net.Mail.SmtpException: Server does not support secure connections.

我猜我应该禁用 SSL 并像以前一样使用它。

有什么建议可以重新发送电子邮件吗?

编辑
我试过没有 SmtpServer.UseDefaultCredentials = false;
我尝试将其设置为 true:SmtpServer.UseDefaultCredentials =true;
我尝试对该行以及以下 //SmtpServer.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);

进行评论

最佳答案

该错误消息通常是由以下原因之一引起的:

  • 不正确的连接设置,例如为安全或非安全连接指定的错误端口
  • 凭据不正确。我会验证用户名和密码组合,以确保凭据正确无误。

关于c# - 系统.Net.Mail.SmtpException : The SMTP server requires a secure connection or the client was not authenticated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13773810/

相关文章:

java - 使用javamail发送邮件抛出错误

sql-server-2008 - SSIS 发送邮件任务限制为地址中的 255 个字符?

c# - smtpClient 不读取 Web.config

c# - 如何发送邮件,邮件正文作为参数并使用线程 - C#

ssl - 使用启用了 SSL 的配置连接 SMTP 服务器时 RemoteCertificateValidationCallback 方法中的 RemoteCertificateNameMismatch

c# - 无法将类型 System.Data.Entity.Core.Objects.ObjectResult 隐式转换为 System.Data.Objects.ObjectResult

c# - 如何编写一个可能返回两种不同类型的方法?

javascript - JSON 数据未保存在 WebAPI 中

c# - 从值中枚举字符串名称

c# - 在 C# 中使用 SMTP 发送电子邮件偶尔会超时