问题描述
我尝试使用Gmail发送邮件,而我得到一个例外是 SMTP服务器要求安全连接或客户端未通过身份验证。服务器响应为:5.7.0必须首先发出STARTTLS命令。 i16sm1806350pag.18 - gsmtp
I am try to sending mail using gmail, and I am getting an exception that is 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. i16sm1806350pag.18 - gsmtp
code我已发送邮件写的
code I have written for sending mail is
MailMessage mail = new MailMessage();
mail.To.Add(txtEmail.Text.Trim());
mail.To.Add("Secondry@gmail.com");
mail.From = new MailAddress("mysendingmail@gmail.com");
mail.Subject = "Confirmation of Registration on Job Junction.";
string Body = "Hi, this mail is to test sending mail using Gmail in ASP.NET";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
// smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential("mysendingmail@gmail.com", "password");
// smtp.Port = 587;
//Or your Smtp Email ID and Password
smtp.UseDefaultCredentials = false;
// smtp.EnableSsl = true;
smtp.Send(mail);
请告诉我的解决方案我不为这个异常得到任何解决方案。
Please tell me solutions I am not getting any solutions for this exceptions.
推荐答案
Gmail要求您使用安全连接。这可以在你的web.config中设置这样的:
Gmail requires you to use a secure connection. This can be set in your web.config like this:
<network host="smtp.gmail.com" enableSsl="true" ... />
或
在SSL应启用Web服务器为好。
请参考以下链接
The SSL should be enable on the webserver as well.Refer following link
Enabling在IIS 7.0 SSL
这篇关于服务器响应为:5.7.0必须首先发出STARTTLS命令。 i16sm1806350pag.18 - gsmtp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!