Note: the .Net 1.1 System.Web.Mail namespace is obsolete as of .Net 2.0. Use the System.Net.Mail namespace in .Net 2.0 apps.
Code: Select all
using (MailMessage mailMessage = new MailMessage(new MailAddress(fromTextBox.Text),
new MailAddress(toTextBox.Text)))
{
mailMessage.Body = bodyTextBox.Text;
mailMessage.Subject = subjectTextBox.Text;
try
{
SmtpClient smtpClient = new SmtpClient(serverAddressTextBox.Text);
smtpClient.Send(mailMessage);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "EMail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}