public bool SendContactMessage(string name , string email, string phone, string location, string message) { string path = HttpContext.Current.Server.MapPath("~" + ConfigurationManager.AppSettings["savedmessagepath"] + String.Format("{0:s}", DateTime.Now).Replace('T', '_').Replace(':', '-') + ".txt"); try { StringBuilder sbBody = new StringBuilder(); sbBody.Append(" Dear Admin," + Environment.NewLine); sbBody.Append(string.Format("A user with the following name {0}, number {1} and location {2}." + Environment.NewLine, name, phone, location)); sbBody.Append("Has sent the following message." + Environment.NewLine); sbBody.Append("----------------------------------------------------------------" + Environment.NewLine + message + Environment.NewLine); //persist message in file using (TextWriter writer = File.CreateText(path)) { writer.WriteLine(sbBody.ToString()); } Email mail = new Email(EmailConstants.SMTPServer, EmailConstants.AdminEmail, EmailConstants.AdminPass); return mail.send_html(EmailConstants.AdminEmail, EmailConstants.AdminName, email, name, "[Global Service Security] - New Enquriy", sbBody.ToString()); } catch(Exception ex) { using (TextWriter writer = File.CreateText(path)) { writer.WriteLine("Email sent failed." + ex.Message); } return false; } }