System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated(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 服务器需要安全连接或客户端未通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证
 
				
         
 
            
        基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				