Server does not support secure connection

asp.netgmailwebforms

Some days before this code perfectly works for me but now it shows exception

 MailMessage mail = new MailMessage();
 mail.To.Add("pramuk97@gmail.com");
 mail.From = new MailAddress("pramuk97@gmail.com");
 mail.To.Add("pramuk97@hotmail.com");
 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("pramuk97@gmail.com", "pwd");
 smtp.EnableSsl = true;
 smtp.Send(mail);

And the exception is
Server does not support secure connections.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: Server does not support secure connections.

Source Error:

Line 78: smtp.Credentials = new System.Net.NetworkCredential("pramuk97@gmail.com", "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

Stack Trace:

[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

Best Answer

Instead of giving SmtpClient smtp = new SmtpClient();

Try this by giving port address

SmtpClient smtpClient = new SmtpClient("smtp.gmail.com",587);
Related Topic