Send an e-Mail

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

This C# code snippet sends out an e-Mail using SMTP.

using System.Net.Mail;
using System.Windows.Forms;
..
void SendEMail
   (string from,   // e.g., "sender@csharp-online.net"
    string to,     // e.g., "receiver@csharp-online.net"
    string subject,// e.g., "Please read this!"
    string body)   // e.g., "Thanks for the memories."
{		
   try
   {  // Construct a new e-mail message 
      SmtpClient client = new SmtpClient (smtpClient);
      client.Send (from, to, subject, body);
   } 
   catch (SmtpException ex)
   {
      MessageBox.Show ( ex.Message, "SendEMail: " + ex.Message,
         MessageBoxButtons.OK, MessageBoxIcon.Error );
   } 
}

Today's Deals: Electronics

Personal tools