The SMTP server requires a secure connection or the client was not authenticated

匿名 (未验证) 提交于 2019-12-03 01:27:01

问题:

I am getting this error

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. e17sm974159fak.34

Web.config

Code file

public void Submit()         {             EnsureCurrentlyValid();             // Send via email             var message = new StringBuilder();             message.AppendFormat("Date: {0:yyyy-MM-dd hh:mm}\n", DateTime.Now);             message.AppendFormat("Email from: {0}\n", Name);             message.AppendFormat("Email: {0}\n", Email);             message.AppendFormat("Message: {0}\n", Message);             SmtpClient smtpClient = new SmtpClient();             MailMessage m = new MailMessage(                 "visitor@mydomain.com", // From                 "emailaccount@gmail.com", // To                 "Suggestion/Comments", // Subject                 message.ToString()); // Body              smtpClient.Send(m);         }

回答1:

Try setting the EnableSsl property to true:

smtpClient.EnableSsl = true;

AFAIK this property can only be set in code and cannot be specified in the config file.



回答2:

Actually you can handle this in your web.config file by adding enableSsl="true". This worked for me and I didn't need to do anything in code.

e.g.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!