我想通过Gmail服务器使用ASP.NET发送电子邮件。这是我的代码,你能帮我解决超时问题吗?使用ASP.NET发送电子邮件
try
{
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
mail.IsBodyHtml = true;
mail.Priority = System.Net.Mail.MailPriority.High;
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Fees Reminder";
mail.Body = "Please, Student ID: " + username + " pay your fees " + sqlFeesValue + ".";
mail.Body += " <html>";
mail.Body += "<body>";
mail.Body += "<table>";
mail.Body += "<tr>";
mail.Body += "<td>User Name : </td><td>" + username + "</td>";
mail.Body += "</tr>";
mail.Body += "<tr>";
mail.Body += "<td>Fees : </td><td> " + sqlFeesValue.ToString() +"</td>";
mail.Body += "</tr>";
mail.Body += "</table>";
mail.Body += "</body>";
mail.Body += "</html>";
smtp.Port = 465;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "passwd");
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mail);
}
catch (Exception error)
{
lblMessage.Visible = true;
lblMessage.Text = error.Message;
}
在此先感谢
查看http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail – 2014-09-19 08:52:09
我想你需要在一个字符串变量中创建一个body变量,然后试试。或者可能是您正在使用错误的端口号 – Amit 2014-09-19 08:54:48
尝试使用端口587.您确定您因为gmail中的新安全设置而没有收到gmail超时? – Alexander 2014-09-19 08:55:44