我想通過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