Eric Bergman-Terrell's Blog

.NET Programming Tip: How to send an e-mail via SMTP
October 4, 2010

Here's the code to send an e-mail using .Net 2.0's System.Net.Mail namespace. Your SMTP server address is specified in the SmtpClient object's constructor. If you don't know your server address you may be able to find it in your e-mail client's configuration.

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.

using (MailMessage mailMessage = new MailMessage(new MailAddress(fromTextBox.Text), 
                                                 new MailAddress(toTextBox.Text)))
  mailMessage.Body    = bodyTextBox.Text;
  mailMessage.Subject = subjectTextBox.Text;

    SmtpClient smtpClient = new SmtpClient(serverAddressTextBox.Text);
  catch (Exception ex)
    MessageBox.Show(ex.Message, "EMail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Keywords: SMTP, Email, System.Net.Mail, SmtpClient, MailAddress, SmtpClient.Send, .NET 1.1, .NET 2.0

Reader Comments

Comment on this Blog Post

Recent Posts

EBTCalc Users: A Desktop Version is Now Available!October 25, 2019
Python Script to Audit MediaMonkey TranscodingAugust 15, 2019
How to decompile Java code with JetBrains IntelliJ IDEA (2018.2.3, Windows 10)October 5, 2018
Java Programming Tip: SWT Photo Frame ProgramOctober 31, 2016
Vault 3 (Desktop) Version 1.63 ReleasedSeptember 9, 2016
"Compliance with Court Orders Act of 2016"April 9, 2016
Disable "Visual Voicemail" on Android / T-MobileJanuary 17, 2016