public void BuildToFromDivision(ProcessMessageArgs args) { var divisionDropList = args.Fields.Where(f => Sitecore.Context.Database.GetItem(f.FieldID).Fields["Field Link"].Value.Equals(Constants.WFM_DivisionDropList_Id, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (divisionDropList != null) { // clear existing `To` value args.To.Remove(0, args.To.Length); // get all comma and semi-colon separated emails from the division string[] emails = divisionDropList.Value.Replace(" ", "").Split(new char[] { ',', ';' }); int totalEmailCount = emails.Length; int currentEmailNumber = 1; foreach (string e in emails) { args.To.Append(e); // delimit so we know how to break up emails in a later step if (currentEmailNumber != totalEmailCount) { args.To.Append("|"); } currentEmailNumber++; } } }
private MailMessage GetMail(ProcessMessageArgs args) { MailMessage mail = new MailMessage(); string[] emails = args.To.ToString().Split('|'); foreach (string address in emails) { mail.To.Add(address); } mail.From = new MailAddress(args.From); mail.Subject = args.Subject.ToString(); mail.Body = args.Mail.ToString(); mail.IsBodyHtml = args.IsBodyHtml; if (args.CC.Length > 0) { mail.CC.Add(args.CC.ToString()); } if (args.BCC.Length > 0) { mail.Bcc.Add(args.BCC.ToString()); } args.Attachments.ForEach(delegate(Attachment attachment) { mail.Attachments.Add(attachment); }); return(mail); }
public void SendEwsEmail(ProcessMessageArgs args) { ISettings settings = new SettingsWrapper(); var exchangeUrl = settings.GetSetting(EwsSettingsPrefix + "ExchangeUrl"); var exchangeVersion = settings.GetSetting(EwsSettingsPrefix + "ExchangeVersion"); var userName = settings.GetSetting(EwsSettingsPrefix + "UserName"); var userDomain = settings.GetSetting(EwsSettingsPrefix + "UserDomain"); var userPassword = settings.GetSetting(EwsSettingsPrefix + "UserPassword"); var fromEmail = settings.GetSetting(EwsSettingsPrefix + "FromEmail"); ExchangeVersion version; if (!Enum.TryParse(exchangeVersion, out version)) { //Default to latest version version = ExchangeVersion.Exchange2013_SP1; } var service = new ExchangeService(version) { Url = new Uri(exchangeUrl), Credentials = !string.IsNullOrEmpty(userDomain) ? new WebCredentials(userName, userPassword, userDomain) : new WebCredentials(userName, userPassword) }; var mail = GetMail(args, service); mail.From = fromEmail; mail.Send(); }
private EmailMessage GetMail(ProcessMessageArgs args, ExchangeService service) { var mail = new EmailMessage(service); if (args.To.Length > 0) { args.To.ToString().Split(';').ToList().ForEach(emailAddress => mail.ToRecipients.Add(emailAddress)); } if (args.CC.Length > 0) { args.CC.ToString().Split(';').ToList().ForEach(emailAddress => mail.CcRecipients.Add(emailAddress)); } if (args.BCC.Length > 0) { args.BCC.ToString().Split(';').ToList().ForEach(emailAddress => mail.BccRecipients.Add(emailAddress)); } mail.Subject = args.Subject.ToString(); mail.Body = args.Mail.ToString(); args.Attachments.ForEach(attachment => mail.Attachments.AddFileAttachment(attachment.Name, attachment.ContentStream)); return(mail); }
public void SendEmail(ProcessMessageArgs args) { SmtpClient smtpClient = new SmtpClient(args.Host); smtpClient.EnableSsl = args.EnableSsl; if (args.Port != 0) { smtpClient.Port = args.Port; } smtpClient.Credentials = args.Credentials; smtpClient.Send(GetMail(args)); }
private EmailMessage GetMail(ProcessMessageArgs args, ExchangeService service) { var mail = new EmailMessage(service); if (args.To.Length > 0) args.To.ToString().Split(';').ToList().ForEach(emailAddress => mail.ToRecipients.Add(emailAddress)); if (args.CC.Length > 0) args.CC.ToString().Split(';').ToList().ForEach(emailAddress => mail.CcRecipients.Add(emailAddress)); if (args.BCC.Length > 0) args.BCC.ToString().Split(';').ToList().ForEach(emailAddress => mail.BccRecipients.Add(emailAddress)); mail.Subject = args.Subject.ToString(); mail.Body = args.Mail.ToString(); args.Attachments.ForEach(attachment => mail.Attachments.AddFileAttachment(attachment.Name, attachment.ContentStream)); return mail; }