public static void Send(string fromEmail, string fromName, string subject, List <string> recipients, string message, string appRoot = "", string themeRoot = "", List <Attachment> attachments = null, bool createCommunicationHistory = true) { var errorMessages = new List <string>(); var emailMessage = new RockEmailMessage(); emailMessage.FromEmail = fromEmail; emailMessage.FromName = fromName; emailMessage.Subject = subject; emailMessage.SetRecipients(recipients); emailMessage.Message = message; emailMessage.ThemeRoot = themeRoot; emailMessage.AppRoot = appRoot; emailMessage.CreateCommunicationRecord = createCommunicationHistory; if (attachments != null) { foreach (var attachment in attachments) { var binaryFile = new BinaryFile(); binaryFile.ContentStream = attachment.ContentStream; binaryFile.FileName = attachment.Name; emailMessage.Attachments.Add(binaryFile); } } emailMessage.Send(out errorMessages); }
public static void Send(Guid emailTemplateGuid, List <RecipientData> recipients, string appRoot = "", string themeRoot = "", bool createCommunicationHistory = true) { using (var rockContext = new RockContext()) { var template = new SystemEmailService(rockContext).Get(emailTemplateGuid); if (template != null) { var errorMessages = new List <string>(); var message = new RockEmailMessage(template); message.SetRecipients(recipients); message.ThemeRoot = themeRoot; message.AppRoot = appRoot; message.CreateCommunicationRecord = createCommunicationHistory; message.Send(out errorMessages); } } }
/// <summary> /// Notifies the admins. /// </summary> /// <param name="subject">The subject.</param> /// <param name="message">The message.</param> /// <param name="appRoot">The application root.</param> /// <param name="themeRoot">The theme root.</param> /// <param name="createCommunicationHistory">if set to <c>true</c> [create communication history].</param> /// <exception cref="System.Exception">Error sending System Email: Could not read Email Medium Entity Type</exception> public static void NotifyAdmins(string subject, string message, string appRoot = "", string themeRoot = "", bool createCommunicationHistory = true) { try { List <Person> personList = null; Guid adminGroup = Rock.SystemGuid.Group.GROUP_ADMINISTRATORS.AsGuid(); using (var rockContext = new RockContext()) { personList = new GroupMemberService(rockContext).Queryable() .Where(m => m.Group.Guid.Equals(adminGroup) && m.GroupMemberStatus == GroupMemberStatus.Active && m.Person.Email != null && m.Person.Email != "") .Select(m => m.Person) .ToList(); } var errorMessages = new List <string>(); var recipients = personList.Select(a => new RockEmailMessageRecipient(a, null)).ToList(); var emailMessage = new RockEmailMessage(); emailMessage.FromEmail = GlobalAttributesCache.Value("OrganizationEmail"); emailMessage.Subject = subject; emailMessage.SetRecipients(recipients); emailMessage.Message = message; emailMessage.ThemeRoot = themeRoot; emailMessage.AppRoot = appRoot; emailMessage.CreateCommunicationRecord = createCommunicationHistory; emailMessage.Send(out errorMessages); } catch (Exception ex) { ExceptionLogService.LogException(ex, HttpContext.Current); } }