Skip to content

Instantly share code, notes, and snippets.

Created June 1, 2012 10:04
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gzuri/2850914 to your computer and use it in GitHub Desktop.
Simple C# send email code snippet
public static bool SendEmail(string mailTo, string subject, string message) {
string mailFrom = ConfigurationManager.AppSettings.Get("MailAddress");
string username = ConfigurationManager.AppSettings.Get("MailUsername");
string password = ConfigurationManager.AppSettings.Get("MailPassword");
int port = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MailOutgoingPort"));
string mailServer = ConfigurationManager.AppSettings.Get("MailServer");
MailMessage mailMessage = new MailMessage(mailFrom, mailTo, subject, message);
mailMessage.BodyEncoding = Encoding.UTF8;
mailMessage.SubjectEncoding = Encoding.UTF8;
SmtpClient smtpClient = new SmtpClient(mailServer, port);
smtpClient.EnableSsl = true;
smtpClient.Credentials = new NetworkCredential(username, password);
return true;
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment