Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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