SMTP服务器需要安全连接,或者客户端未通过身份验证.

问题描述:

System.Net.Mail.SmtpClient smtpClient = new SmtpClient(strSmtpServer, int.Parse(strPort));
		smtpClient.UseDefaultCredentials = false;

		System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
		System.Net.NetworkCredential basicCredential = new System.Net.NetworkCredential();
		try
		{
			
			basicCredential.UserName = strSender;
			basicCredential.Password = strSenderPass;

			System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress(strSender, "NameToDisplay");
			message.From = fromAddress;//here you can set address
			message.To.Add(strReceiver);//here you can add multiple to
			message.Subject = strSubject;//subject of email
			//message.CC.Add("cc@site.com");//ccing the same email to other email address
			//message.Bcc.Add(new MailAddress("bcc@site.com"));//here you can add bcc address

			message.IsBodyHtml = true;	//To determine email body is html or not
			message.Body = strMessage;
			smtpClient.EnableSsl = true;
			smtpClient.Send(message);
		}

		catch (Exception ex)
		{
			return false;
		}

		return true;


我收到以下异常:
SMTP服务器需要安全连接,或者客户端未通过身份验证.服务器响应为:5.5.1需要身份验证.进一步了解...

为什么?以上方法有什么错误吗?

帮帮我.
谢谢.


I get the following Exception:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at...

Why? Is there any mistake in above method?

Help me.
Thanks.

错误提示这是身份验证问题.确保已设置防火墙权限,并且使用的凭据正确且允许使用.

另外,请确保已在Web.Config中配置了SMTP配置:
Error suggests that it''s an authentication issue. Make sure that the Firewall permissions are in place and the credentials used are correct and allowed.

Also, make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>


如果需要,请查看此Microsoft Video教程:
使用ASP.NET发送来自网站的电子邮件 [


If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]


您需要进入gmail帐户并确认服务器的IP地址,然后尝试发送.
在网络配置中enablesl = true.
这是工作.........
hi you need to going to gmail account and confirm the Ip address your server and then try to send .
in the web config enablessl = true .
this is work............