有些日子,在這之前的代碼完全對我的作品,但現在它顯示例外服務器不支持安全連接
MailMessage mail = new MailMessage();
mail.To.Add("[email protected]");
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "from bhsbiet souvenir 2012";
mail.Body = TextBox5.Text;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "pwd");
smtp.EnableSsl = true;
smtp.Send(mail);
並將異常 服務器不支持安全連接。
描述:執行當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
異常詳細信息:System.Net.Mail.SmtpException:服務器不支持安全連接。
源錯誤:
Line 78: smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "mukund1375");Line 79: smtp.EnableSsl = true;Line 80: smtp.Send(mail); Line 81: TextBox5.Text = "message sent";Line 82: TextBox5.ReadOnly = true;
Source File: E:\bhsbiet\bhsbiet\home.aspx.cs Line: 80
堆棧跟蹤:
[SmtpException: Server does not support secure connections.] System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +1223423 System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +222 System.Net.Mail.SmtpClient.GetConnection() +50 System.Net.Mail.SmtpClient.Send(MailMessage message) +1772 bhsbiet.home.buttonx_click(Object sender, EventArgs e) in E:\bhsbiet\bhsbiet\home.aspx.cs:80 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
可能重複(http://stackoverflow.com/questions/32260試試這個/發送電子郵件,在淨通過Gmail郵箱) – jrummell 2012-02-16 21:58:28