I am trying to send email via my web, I research for help no luck. Still receive error: smtpexception was unhandled by user code
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]");
msg.To.Add(TextBox3.Text);
msg.Subject = TextBox4.Text;
msg.Body = TextBox5.Text;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
System.Net.NetworkCredential netCred = new System.Net.NetworkCredential();
netCred.UserName = "[email protected]";
netCred.Password = "11111111";
smtp.UseDefaultCredentials = true;
smtp.Credentials = netCred;
smtp.Port = 465;
smtp.EnableSsl = true;
smtp.Send(msg);
try
{
smtp.Send(msg);
Label1.Text = "Your E-Mail Sent Great Job!!!!";
}
catch (Exception ex)
{
//Handle your exception here
Label1.Text = ex.Message + " " + "Oeps, something when wrong when we tried to send the email";
return;
}
}
when i run it shows me this error highlighting smtp.Send(message);:
SmtpException was unhandled by the user code and Failure sending mail.
System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at IntroAsp.net.EmailMsg.Button1_Click(Object sender, EventArgs e) in c:\Users\Regev\Documents\Visual Studio 2013\Projects\IntroAsp.net\IntroAsp.net\EmailMsg.aspx.cs:line 46
less secure apps
– Mad Myche