Published in: C#
A simple function to send an email in .NET. You can add this to a utility class and use as needed. A more complicated example can embed HTML templates for various communications.
// Make mail easy to send. public static string SendMail(string from, string to, string subject, string body, string smtp) { // Create new MailMessage Object //message.Bcc.Add("someone@tobcc.com"); message.IsBodyHtml = true; // Create new SmtpClient Object try { // Send eMail and return 1 if successful // otherwise return error message mailClient.Send(message); return "1"; } catch (System.Net.Mail.SmtpException e) { // create or append errors to a log file Err.ErrorLog(System.Web.HttpContext.Current.Server.MapPath("/logs/ErrorLog.log"), e.InnerException.Message); return e.InnerException.Message; } }
You need to login to post a comment.
