private void SendContactEmail(ContactUs record) { //admin email var body = ""; var template = (new Beweb.TextBlock("Contact Us Notification Email Text", Util.GetSiteName() + " Admin: Contact Request.", @"<p>Dear Admin,</p> <p>A member of the public has requested that you contact them. Here are the details:</p> <p>[--WEBLINK--]</p> <p>Name:[--Name--]</p> <p>Email: [--Email--]</p> <p>Subject: [--Subject--]</p> <p>Message:<br>[--Message--]</p>")); body = template.RawBody; // use raw body for email, not bodytexthtml which has links to the site removed from it / replaced with nothing var url = Web.BaseUrl + "Admin/ContactUsAdmin/Edit/" + record.ID; var link = @"<a href=""" + url + @""">Click here</a>"; body = body.Replace("[--WEBLINK--]", link); body = body.Replace("[--Name--]", record.Name); body = body.Replace("[--Email--]", record.Email); body = body.Replace("[--Subject--]", record.Subject); body = body.Replace("[--Message--]", record.Message); //send email to admin var email = new Beweb.ElectronicMail(); email.ToAddress = Util.GetSetting("EmailToAddress"); email.Subject = template.Title; email.BodyHtml = body; email.Send(true); }
public void SendIfHasLines(string emailTo) { if (HasLines) { var email = new ElectronicMail() { Subject = ReportTitle }; email.ToAddress = emailTo ?? SendEMail.EmailToAddress; email.BodyHtml = ToHtml(); email.Send(true); } }
/// <summary> /// Sends a dump off to the reporting system (http twitch or errors email, whichever is reachable) /// </summary> public static bool PostErrorReport(Logging.DiagnosticData dump) { bool wasLogged = false; string subject = String.Format("ERROR on: {1} ({0})", dump.HttpStatusCode, ConfigurationManager.AppSettings.Get("ServerIsLVE") ?? Web.Request.ServerVariables["REMOTE_ADDR"]); subject += " | " + dump.ErrorMessage.StripTags(); // try sending http post first string postUrl = Util.GetSetting("ErrorPostUrl", "(none)"); if (postUrl != "(none)") { try { var throttle = Util.GetSettingInt("ThrottleSameError", 60); var client = new WebClient(); var data = new NameValueCollection(); data.Add("site", ConfigurationManager.AppSettings.Get("ServerIsLVE")); data.Add("sender", SendEMail.EmailFromAddress); data.Add("subject", subject.Left(168)); data.Add("errorCode", dump.HttpStatusCode + ""); data.Add("ErrorMessage", dump.ErrorMessage); data.Add("source", dump.Source); data.Add("FailureUrl", dump.Url); data.Add("WebsiteUrl", Web.BaseUrl); data.Add("user", dump.User); data.Add("dignostics", dump.ToHtml()); data.Add("ErrorReportGuid", dump.ErrorReportGuid + ""); data.Add("NumInstances", dump.NumberOfTimesSinceLastErrorReport + ""); data.Add("Throttle", throttle + ""); var response = client.UploadValues(postUrl, data); //var str = System.Text.Encoding.Default.GetString(response); if (response.Length > 0) { wasLogged = true; } } catch (Exception) { } } if (!wasLogged) { // if post failed, send email string emailTo = ConfigurationManager.AppSettings.Get("EmailAboutError"); var email = new ElectronicMail(); email.Subject = subject.Left(168); email.BodyHtml = dump.ToHtml(); email.ToAddress = emailTo; wasLogged = email.Send(false); } return(wasLogged); }
/// <summary> /// send error email /// </summary> /// <param name="to"></param> /// <param name="subject"></param> /// <param name="body"></param> /// <param name="serverType"></param> /// <returns>error message or blank</returns> public static string SendErrorEmail(string to, string subject, string body, string serverType) { string returnValue = ""; if (!String.IsNullOrEmpty(to)) { //defaults string from = Beweb.Util.GetSetting("EmailFromAddress", "*****@*****.**"); string host = Beweb.Util.GetSetting("EmailHost", "localhost"); // local will possibly not work either int port = Convert.ToInt32(Beweb.Util.GetSetting("EmailPort", "25")); //port = (port == 0) ? 25 : port; var email = new ElectronicMail(); email.FromAddress = from; email.ToAddress = to; email.Subject = subject; email.BodyPlain = body; email.Send(false); returnValue = email.ErrorResult; //MailMessage message = new MailMessage(); //message.From = new MailAddress(from); ////message.To.Add(new MailAddress(to)); //string[] toAddresses = to.Split(';'); //foreach (string address in toAddresses) //{ // message.To.Add(new MailAddress(address)); //} //message.Subject = subject; //message.Body = body; //SmtpClient client = new SmtpClient(host, port); //try //{ // client.Send(message); //} catch (SmtpException e) //{ // if (e.InnerException != null) // { // returnValue = e.InnerException.Message; // } else // { // returnValue = e.Message; // } //} } return(returnValue); }