【发布时间】:2020-02-21 22:07:05
【问题描述】:
在 C# 中,我尝试使用 Gmail 发送电子邮件。这是我的代码:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("myemail@gmail.com");
mail.To.Add("myemailto@gmail.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
SmtpServer.Port = 465;
SmtpServer.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "mypsw");
SmtpServer.UseDefaultCredentials = false;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
我得到错误:
{System.Net.Mail.SmtpException:发送邮件失败。 ---> System.IO.IOException:无法从传输连接中读取数据:连接已关闭。
在 System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
【问题讨论】:
-
这个答案stackoverflow.com/questions/13506623/…建议端口587
标签: c# smtp gmail smtpclient