Muhammad Nadeem

Muhammad Nadeem

  • NA
  • 548
  • 65.8k

Mail message in Web Application

Apr 28 2016 12:10 AM
This is my code but I get exception error why because my all code is to the point and correct.
protected void ButtonSend_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage(TextBoxFrom.Text, TextBoxTo.Text, TextBoxSubject.Text, TextBoxBody.Text);
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Credentials = new System.Net.NetworkCredential(TextBoxEmail.Text, TextBoxPassword.Text);
smtp.EnableSsl = true;
smtp.Send(mail);
Response.Write("Message sent successfully!");
}
catch (Exception ex)
{
Response.Write(ex.Message + " Some error's !");
}
}
Please teach me. Thanks a lot. 

Answers (5)