System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated(System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证)
本文介绍了System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to send email with my website's address from a C# application.
This worked fine for several months until recently. (maybe my provider changes some things or someone else changed settings)

代码如下:

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

这是错误:

SMTP 服务器需要安全连接或客户端未通过身份验证.服务器响应为:需要 SMTP 身份验证.

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

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

Looking at other questions I tried what they suggested, to make SmtpServer.EnableSsl = true. This didn't work at all. It gave the following:

System.Net.Mail.SmtpException:服务器不支持安全连接.

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

我猜我应该禁用 SSL 并按照以前的方式使用它.

I'm guessing I should disable SSL and have it the way it was before.

有什么建议可以让电子邮件再次发送工作吗?

Any suggestions how to make email sending work again?

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

推荐答案

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

That error message is typically caused by one of the following:

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

这篇关于System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)