无法使用 Gmail SMTP 发送电子邮件
Cant send email using Gmail SMTP
我有一个带有联系表的网站 - 我希望将反馈发送到我的 gmail 帐户。为此,我创建了另一个虚拟 gmail 帐户来发送这些消息。代码如下所示
MailMessage msg = new MailMessage();
msg.To.Add("to_mail@gmail.com");
msg.From = new MailAddress("from_mail@gmail.com");
msg.Subject = "Feedback";
msg.Body = txtName.Text + " " + txtEmail.Text + " " + txtMessage.Text;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 587;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("from_mail@gmail.com", "password");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Send(msg);
当我从我的 VS 项目的本地主机 运行 这段代码工作正常,但是一旦我编译它并上传到网络,它就停止工作并出现这个错误。
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
有谁知道是什么原因造成的以及如何解决?我已经在我的 gmail 帐户中启用了对安全性较低的应用程序的访问。 465端口也试过了,还是不行
非常感谢,约瑟夫
可能原因:
In gmail, If the current login region and the previous login region is
different, then gmail ask us some security questions before login. So
better try to login once via browser in the system which you are using
that C# app.
终于找到答案了。必须在我的 "From" Gmail 帐户登录后单击此 link。
我有一个带有联系表的网站 - 我希望将反馈发送到我的 gmail 帐户。为此,我创建了另一个虚拟 gmail 帐户来发送这些消息。代码如下所示
MailMessage msg = new MailMessage();
msg.To.Add("to_mail@gmail.com");
msg.From = new MailAddress("from_mail@gmail.com");
msg.Subject = "Feedback";
msg.Body = txtName.Text + " " + txtEmail.Text + " " + txtMessage.Text;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 587;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("from_mail@gmail.com", "password");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Send(msg);
当我从我的 VS 项目的本地主机 运行 这段代码工作正常,但是一旦我编译它并上传到网络,它就停止工作并出现这个错误。
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
有谁知道是什么原因造成的以及如何解决?我已经在我的 gmail 帐户中启用了对安全性较低的应用程序的访问。 465端口也试过了,还是不行
非常感谢,约瑟夫
可能原因:
In gmail, If the current login region and the previous login region is different, then gmail ask us some security questions before login. So better try to login once via browser in the system which you are using that C# app.
终于找到答案了。必须在我的 "From" Gmail 帐户登录后单击此 link。