public ActionResult SubmitReportForm(RedYellowCardReportFormModel model) { //verify Google reCAPTCHA if (string.IsNullOrEmpty(Request["g-recaptcha-response"])) { ModelState.AddModelError("reCAPTCHA", "Please complete the reCAPTCHA"); return(CurrentUmbracoPage()); } else { CaptchaResponse response = ValidateCaptcha(Request["g-recaptcha-response"]); if (!response.Success) { ModelState.AddModelError("reCAPTCHA", "The reCAPTCHA is incorrect!"); return(CurrentUmbracoPage()); } } if (!ModelState.IsValid) { return(CurrentUmbracoPage()); } // Look for multiple receivers on Umbraco page List <string> managerEmailList = new List <string>(); string managerEmail1 = CurrentPage.Parent.GetPropertyValue <string>("notifyEmail"); managerEmailList.Add(managerEmail1); string managerEmail2 = CurrentPage.Parent.GetPropertyValue <string>("notifyEmail2"); managerEmailList.Add(managerEmail2); string managerEmail3 = CurrentPage.Parent.GetPropertyValue <string>("notifyEmail3"); managerEmailList.Add(managerEmail3); string managerEmail = ""; for (int i = 0; i < managerEmailList.Count(); i++) { if ((managerEmailList[i].Trim() != "") && (i != managerEmailList.Count() - 1)) { managerEmail += managerEmailList[i] + ","; } if ((managerEmailList[i].Trim() != "") && (i == managerEmailList.Count() - 1)) { managerEmail += managerEmailList[i]; } } SendNotificationToManager(model, managerEmail); SendAutoResponder(model); return(CurrentUmbracoPage()); }
private void SendAutoResponder(RedYellowCardReportFormModel model) { var subject = string.Format("Report form submission on {0}.", this.Request.Url.Host); var message = string.Format("Hi {0}, Thank you for your submission. We'll review your submission as soon as possible. <br/> Cheers, <br> Taranaki Rugby Referee Association <br/>", model.RefereeName); using (var email = new MailMessage { Subject = subject, To = { model.RefereeEmail }, From = new MailAddress("*****@*****.**"), Body = message, IsBodyHtml = true }) { var developerEmail = ConfigurationManager.AppSettings["DeveloperEmail"]; var isSendCopyToDev = bool.Parse(ConfigurationManager.AppSettings["SendEmailCopyToDev"]); if (isSendCopyToDev) { email.Bcc.Add(developerEmail); } //Send email try { //Connect to SMTP credentials set in web.config SmtpClient smtp = new SmtpClient(); //Try & send the email with the SMTP settings smtp.Send(email); } catch (Exception) { throw; } } }