5
Answers

Mail message in Web Application

M CH

M CH

8y
443
1
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)