public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e) { MailAddress FromMailAddress; if (string.IsNullOrEmpty(this.FromEmail)) { var settings = UmbracoConfig.For.UmbracoSettings(); FromMailAddress = new MailAddress(settings.Content.NotificationEmailAddress); } else { string fromEmailField = this.FromEmail; string fromNameField = ""; bool fromEmailFound = false; bool fromNameFound = false; try { foreach (RecordField rf in record.RecordFields.Values) { string refinedCaption = "{" + rf.Field.Caption.ToLower().Replace(" ", "") + "}"; if (!fromEmailFound && refinedCaption == this.FromEmail.ToLower()) { fromEmailField = rf.ValuesAsString(); fromEmailFound = true; } else if (!fromNameFound && !String.IsNullOrEmpty(this.FromName) && refinedCaption == this.FromName.ToLower()) { fromNameField = rf.ValuesAsString(); fromNameFound = true; } //dont go any further to not waste time looking for something already there if (fromEmailFound && fromNameFound) { break; } } if (fromNameFound) { FromMailAddress = new MailAddress(fromEmailField, fromNameField); } else if (!string.IsNullOrEmpty(this.FromName)) { FromMailAddress = new MailAddress(fromEmailField, this.FromName); } else { FromMailAddress = new MailAddress(fromEmailField); } } catch (Exception ex) { var settings = UmbracoConfig.For.UmbracoSettings(); FromMailAddress = new MailAddress(settings.Content.NotificationEmailAddress); } } var mailMessage = new MailMessage { From = FromMailAddress, Subject = this.Subject, ReplyTo = FromMailAddress, IsBodyHtml = true, BodyEncoding = Encoding.UTF8 }; if (this.Email.Contains(";")) { foreach (string email in this.Email.Split(';')) { mailMessage.To.Add(email.Trim()); } } else { mailMessage.To.Add(this.Email); } XmlNode xml = record.ToXml(new System.Xml.XmlDocument()); // we will by default set the body to the record xml so if no xslt file is // present we atleast get the raw data. string result = xml.OuterXml; if (!string.IsNullOrEmpty(this.XsltFile)) { result = XsltHelper.TransformXML(xml, this.XsltFile, null); } mailMessage.Body = "<p>" + Message + "</p><br />" + result; var smtpClient = new SmtpClient { EnableSsl = false }; if (WebConfigurationManager.AppSettings.AllKeys.Contains("contourContribUseSsl") && WebConfigurationManager.AppSettings["contourContribUseSsl"].ToLower() == true.ToString().ToLower()) { smtpClient.EnableSsl = true; } smtpClient.Send(mailMessage); return WorkflowExecutionStatus.Completed; }
public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e) { MailAddress FromMailAddress; if (string.IsNullOrEmpty(this.FromEmail)) { var settings = UmbracoConfig.For.UmbracoSettings(); FromMailAddress = new MailAddress(settings.Content.NotificationEmailAddress); } else { string fromEmailField = this.FromEmail; string fromNameField = ""; bool fromEmailFound = false; bool fromNameFound = false; try { foreach (RecordField rf in record.RecordFields.Values) { string refinedCaption = "{" + rf.Field.Caption.ToLower().Replace(" ", "") + "}"; if (!fromEmailFound && refinedCaption == this.FromEmail.ToLower()) { fromEmailField = rf.ValuesAsString(); fromEmailFound = true; } else if (!fromNameFound && !String.IsNullOrEmpty(this.FromName) && refinedCaption == this.FromName.ToLower()) { fromNameField = rf.ValuesAsString(); fromNameFound = true; } //dont go any further to not waste time looking for something already there if (fromEmailFound && fromNameFound) { break; } } if (fromNameFound) { FromMailAddress = new MailAddress(fromEmailField, fromNameField); } else if (!string.IsNullOrEmpty(this.FromName)) { FromMailAddress = new MailAddress(fromEmailField, this.FromName); } else { FromMailAddress = new MailAddress(fromEmailField); } } catch (Exception ex) { var settings = UmbracoConfig.For.UmbracoSettings(); FromMailAddress = new MailAddress(settings.Content.NotificationEmailAddress); } } var mailMessage = new MailMessage { From = FromMailAddress, Subject = this.Subject, ReplyTo = FromMailAddress, IsBodyHtml = true, BodyEncoding = Encoding.UTF8 }; if (this.Email.Contains(";")) { foreach (string email in this.Email.Split(';')) { mailMessage.To.Add(email.Trim()); } } else { mailMessage.To.Add(this.Email); } XmlNode xml = record.ToXml(new System.Xml.XmlDocument()); // we will by default set the body to the record xml so if no xslt file is // present we atleast get the raw data. string result = xml.OuterXml; if (!string.IsNullOrEmpty(this.XsltFile)) { result = XsltHelper.TransformXML(xml, this.XsltFile, null); } mailMessage.Body = "<p>" + Message + "</p><br />" + result; var smtpClient = new SmtpClient { EnableSsl = false }; if (WebConfigurationManager.AppSettings.AllKeys.Contains("contourContribUseSsl") && WebConfigurationManager.AppSettings["contourContribUseSsl"].ToLower() == true.ToString().ToLower()) { smtpClient.EnableSsl = true; } smtpClient.Send(mailMessage); return(WorkflowExecutionStatus.Completed); }