public formResponse sendForm(formRequest request) { formResponse nr = new formResponse(); nr.Result = "1"; nr.Msg = string.Empty; try { // start Node Factory Node page = new Node(request.Id); string autoResponderEmail = string.Empty; string autoResponderId = string.Empty; if (page.GetProperty("emailField") != null) { autoResponderId = page.GetProperty("emailField").Value; } // construct the email message int rowCount = 0; string message = "<html><head></head><body><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-family: sans-serif; font-size: 13px; color: #222; border-collapse: collapse;\">"; for (int i = 0; i < request.Values.Length; i++) { string name = request.Names[i]; //string nodeName = string.Empty; int index = request.FieldIds[i].LastIndexOf('_') + 1; if (index > 0) { string fullId = request.FieldIds[i].Substring(index, request.FieldIds[i].Length - index); if (fullId == autoResponderId) { autoResponderEmail = request.Values[i]; } int id; if (int.TryParse(fullId, out id)) { Node node = new Node(id); if (node != null) { //nodeName = node.Name; name = node.Name; try { if (node.GetProperty("label").Value.Length > 0) { name = node.GetProperty("label").Value; } else if (node.NodeTypeAlias == "PliableText") { if (node.GetProperty("defaultValue").Value.Length > 0) { name = node.GetProperty("defaultValue").Value; } } } catch { } } } } if (name.Length > 0) { rowCount++; try { if (rowCount % 2 == 0) { message += string.Format("<tr><td style=\"background-color: #ffffff; padding: 4px 8px; vertical-align: top; width: 120px;\">{0}</td><td style=\"background-color: #ffffff; padding: 4px 8px; vertical-align: top;\">{1}</td></tr>", name, request.Values[i]); } else { message += string.Format("<tr><td style=\"background-color: #ebf5ff; padding: 4px 8px; vertical-align: top; width: 120px;\">{0}</td><td style=\"background-color: #ebf5ff; padding: 4px 8px; vertical-align: top;\">{1}</td></tr>", name, request.Values[i]); } } catch { } } } message += "</table></body></html>"; // determine the to address string emailTo = page.GetProperty("toAddress").Value; if (string.IsNullOrEmpty(emailTo)) { emailTo = ConfigurationManager.AppSettings["PliableForm.defaultToAddress"]; if (emailTo == null) { emailTo = umbraco.library.GetDictionaryItem("PliableForm.defaultToAddress"); } } string subject = page.GetProperty("emailSubject").Value; if (string.IsNullOrEmpty(subject)) { subject = ConfigurationManager.AppSettings["PliableForm.defaultEmailSubject"]; if (subject == null) { subject = umbraco.library.GetDictionaryItem("PliableForm.defaultEmailSubject"); } } req = request; MatchEvaluator reEval = new MatchEvaluator(this.replaceFields); // send the email SendEmailMessage(emailTo, message, Regex.Replace(subject, "{([^}]+)}", reEval), true); nr.Result = "2"; // send the autoresponder email if (!string.IsNullOrEmpty(autoResponderEmail)) { string ARbody = string.Empty; try { ARbody = page.GetProperty("autoResponderText").Value; } catch { /* Swallow Exception */ } bool ARisHtml = false; if (string.IsNullOrEmpty(ARbody)) { ARbody = page.GetProperty("autoResponderHtml").Value; ARbody = ARbody.Replace("[OriginalMessage]", message.Replace("<html><head></head><body>", string.Empty).Replace("</body></html>", string.Empty)); ARisHtml = true; } ARbody = Regex.Replace(ARbody, "{([^}]+)}", reEval); SendEmailMessage(autoResponderEmail, ARbody, Regex.Replace(page.GetProperty("autoResponderSubject").Value, "{([^}]+)}", reEval), ARisHtml); } } catch (Exception ex) { nr.Result = "3"; var innerEx = string.Empty; if (ex.InnerException != null) { innerEx = ex.InnerException.StackTrace; } nr.Msg = string.Format("Message: {0} StackTrace: {1} {2}", ex.Message, ex.StackTrace, innerEx); } return(nr); }
public formResponse sendForm(formRequest request) { formResponse nr = new formResponse(); nr.Result = "1"; nr.Msg = string.Empty; try { // start Node Factory Node page = new Node(request.Id); string autoResponderId = page.GetProperty("emailField").Value; string autoResponderEmail = string.Empty; // construct the email message int rowCount = 0; string message = "<html><head></head><body><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-family: sans-serif; font-size: 13px; color: #222; border-collapse: collapse;\">"; for (int i = 0; i < request.Values.Length; i++) { string name = request.Names[i]; int index = request.FieldIds[i].LastIndexOf('_') + 1; if (index > 0) { string fullId = request.FieldIds[i].Substring(index, request.FieldIds[i].Length - index); if (fullId == autoResponderId) { autoResponderEmail = request.Values[i]; } int id; if (int.TryParse(fullId, out id)) { Node node = new Node(id); if (node != null) { if (node.GetProperty("label").Value.Length > 0) { name = node.GetProperty("label").Value; } else if (node.NodeTypeAlias == "PliableText") { if (node.GetProperty("defaultValue").Value.Length > 0) { name = node.GetProperty("defaultValue").Value; } } } } } if (name.Length > 0) { rowCount++; if (rowCount % 2 == 0) { message += string.Format("<tr><td style=\"background-color: #ffffff; padding: 4px 8px; vertical-align: top; width: 120px;\">{0}</td><td style=\"background-color: #ffffff; padding: 4px 8px; vertical-align: top;\">{1}</td></tr>", name, request.Values[i]); } else { message += string.Format("<tr><td style=\"background-color: #ebf5ff; padding: 4px 8px; vertical-align: top; width: 120px;\">{0}</td><td style=\"background-color: #ebf5ff; padding: 4px 8px; vertical-align: top;\">{1}</td></tr>", name, request.Values[i]); } } } message += "</table></body></html>"; // determine the to address string emailTo = page.GetProperty("toAddress").Value; if (emailTo == null || emailTo.Length < 1) { emailTo = ConfigurationManager.AppSettings.Get("PliableForm.defaultToAddress"); if (emailTo == null) { emailTo = umbraco.library.GetDictionaryItem("PliableForm.defaultToAddress"); } } string subject = page.GetProperty("emailSubject").Value; if (subject == null || subject.Length < 1) { subject = ConfigurationManager.AppSettings.Get("PliableForm.defaultEmailSubject"); if (subject == null) { subject = umbraco.library.GetDictionaryItem("PliableForm.defaultEmailSubject"); } } req = request; MatchEvaluator reEval = new MatchEvaluator(this.replaceFields); // send the email SendEmailMessage(emailTo, message, Regex.Replace(subject, "{([^}]+)}", reEval), true); nr.Result = "2"; // send the autoresponder email if (autoResponderEmail.Length > 4) { string ARbody = page.GetProperty("autoResponderText").Value; bool ARisHtml = false; if (ARbody.Length < 1) { ARbody = page.GetProperty("autoResponderHtml").Value; ARisHtml = true; } ARbody = Regex.Replace(ARbody, "{([^}]+)}", reEval); SendEmailMessage(autoResponderEmail, ARbody, Regex.Replace(page.GetProperty("autoResponderSubject").Value, "{([^}]+)}", reEval), ARisHtml); } } catch (Exception ex) { nr.Result = "3"; nr.Msg = ex.Message; } return nr; }