Muhammad Nadeem

Muhammad Nadeem

  • NA
  • 548
  • 66.2k

Mail Message in Window form application

Feb 17 2016 2:53 AM
Dear Sir,
                 I have a code for mail message in window form application but I get exception error after running. Code is here
private void buttonSend_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage(textBoxFrom.Text, textBoxTo.Text, textBoxSubject.Text, richTextBoxMsgBody.Text);
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Credentials = new System.Net.NetworkCredential(textBoxOwnE.Text, textBoxPass.Text);
smtp.EnableSsl = true;
smtp.Send(mail);
MessageBox.Show("Your e-mail is sent suuccessfully!", "Message Sent", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Please help me . I shell be very thankful to you for this kindness. 

Answers (2)