/// <summary> /// Creates the email communication. /// </summary> /// <param name="recipientEmails">The recipient emails.</param> /// <param name="fromName">From name.</param> /// <param name="fromAddress">From address.</param> /// <param name="replyTo">The reply to.</param> /// <param name="subject">The subject.</param> /// <param name="message">The message.</param> /// <param name="bulkCommunication">if set to <c>true</c> [bulk communication].</param>\ /// <param name="sendDateTime">The send date time.</param> /// <param name="recipientStatus">The recipient status.</param> /// <param name="senderPersonAliasId">The sender person alias identifier.</param> /// <returns></returns> public Communication CreateEmailCommunication ( List <string> recipientEmails, string fromName, string fromAddress, string replyTo, string subject, string message, bool bulkCommunication, DateTime?sendDateTime, CommunicationRecipientStatus recipientStatus = CommunicationRecipientStatus.Delivered, int?senderPersonAliasId = null) { var recipients = new PersonService((RockContext)Context) .Queryable() .Where(p => recipientEmails.Contains(p.Email)) .ToList(); if (!recipients.Any()) { return(null); } var communication = new Communication { CommunicationType = CommunicationType.Email, Status = CommunicationStatus.Approved, SenderPersonAliasId = senderPersonAliasId }; communication.FromName = fromName.TrimForMaxLength(communication, "FromName"); communication.FromEmail = fromAddress.TrimForMaxLength(communication, "FromEmail"); communication.ReplyToEmail = replyTo.TrimForMaxLength(communication, "ReplyToEmail"); communication.Subject = subject.TrimForMaxLength(communication, "Subject"); communication.Message = message; communication.IsBulkCommunication = bulkCommunication; communication.FutureSendDateTime = null; communication.SendDateTime = sendDateTime; Add(communication); // add each person as a recipient to the communication foreach (var person in recipients) { var personAliasId = person.PrimaryAliasId; if (!personAliasId.HasValue) { continue; } var communicationRecipient = new CommunicationRecipient { PersonAliasId = personAliasId.Value, Status = recipientStatus, SendDateTime = sendDateTime }; communication.Recipients.Add(communicationRecipient); } return(communication); }
/// <summary> /// Creates the email communication. /// </summary> /// <param name="recipientEmails">The recipient emails.</param> /// <param name="fromName">From name.</param> /// <param name="fromAddress">From address.</param> /// <param name="replyTo">The reply to.</param> /// <param name="subject">The subject.</param> /// <param name="htmlMessage">The HTML message.</param> /// <param name="textMessage">The text message.</param> /// <param name="bulkCommunication">if set to <c>true</c> [bulk communication].</param> /// <param name="recipientStatus">The recipient status.</param> /// <param name="senderPersonAliasId">The sender person alias identifier.</param> /// <returns></returns> public Communication CreateEmailCommunication( List<string> recipientEmails, string fromName, string fromAddress, string replyTo, string subject, string htmlMessage, string textMessage, bool bulkCommunication, CommunicationRecipientStatus recipientStatus = CommunicationRecipientStatus.Delivered, int? senderPersonAliasId = null ) { var recipients = new PersonService( (RockContext)this.Context ) .Queryable() .Where( p => recipientEmails.Contains( p.Email ) ) .ToList(); if ( recipients.Any() ) { Rock.Model.Communication communication = new Rock.Model.Communication(); communication.Status = CommunicationStatus.Approved; communication.SenderPersonAliasId = senderPersonAliasId; communication.Subject = subject; Add( communication ); communication.IsBulkCommunication = bulkCommunication; communication.MediumEntityTypeId = EntityTypeCache.Read( "Rock.Communication.Medium.Email" ).Id; communication.FutureSendDateTime = null; // add each person as a recipient to the communication foreach ( var person in recipients ) { int? personAliasId = person.PrimaryAliasId; if ( personAliasId.HasValue ) { var communicationRecipient = new CommunicationRecipient(); communicationRecipient.PersonAliasId = personAliasId.Value; communicationRecipient.Status = recipientStatus; communication.Recipients.Add( communicationRecipient ); } } // add the MediumData to the communication communication.MediumData.Clear(); communication.MediumData.Add( "FromName", fromName ); communication.MediumData.Add( "FromAddress", fromAddress ); communication.MediumData.Add( "ReplyTo", replyTo ); communication.MediumData.Add( "Subject", subject ); communication.MediumData.Add( "HtmlMessage", htmlMessage ); communication.MediumData.Add( "TextMessage", textMessage ); return communication; } return null; }
/// <summary> /// Creates the email communication. /// </summary> /// <param name="recipientEmails">The recipient emails.</param> /// <param name="fromName">From name.</param> /// <param name="fromAddress">From address.</param> /// <param name="replyTo">The reply to.</param> /// <param name="subject">The subject.</param> /// <param name="htmlMessage">The HTML message.</param> /// <param name="textMessage">The text message.</param> /// <param name="bulkCommunication">if set to <c>true</c> [bulk communication].</param> /// <param name="recipientStatus">The recipient status.</param> /// <param name="senderPersonAliasId">The sender person alias identifier.</param> /// <returns></returns> public Communication CreateEmailCommunication( List <string> recipientEmails, string fromName, string fromAddress, string replyTo, string subject, string htmlMessage, string textMessage, bool bulkCommunication, CommunicationRecipientStatus recipientStatus = CommunicationRecipientStatus.Delivered, int?senderPersonAliasId = null) { var recipients = new PersonService((RockContext)this.Context) .Queryable() .Where(p => recipientEmails.Contains(p.Email)) .ToList(); if (recipients.Any()) { Rock.Model.Communication communication = new Rock.Model.Communication(); communication.Status = CommunicationStatus.Approved; communication.SenderPersonAliasId = senderPersonAliasId; communication.Subject = subject; Add(communication); communication.IsBulkCommunication = bulkCommunication; communication.MediumEntityTypeId = EntityTypeCache.Read("Rock.Communication.Medium.Email").Id; communication.FutureSendDateTime = null; // add each person as a recipient to the communication foreach (var person in recipients) { int?personAliasId = person.PrimaryAliasId; if (personAliasId.HasValue) { var communicationRecipient = new CommunicationRecipient(); communicationRecipient.PersonAliasId = personAliasId.Value; communicationRecipient.Status = recipientStatus; communication.Recipients.Add(communicationRecipient); } } // add the MediumData to the communication communication.MediumData.Clear(); communication.MediumData.Add("FromName", fromName); communication.MediumData.Add("FromAddress", fromAddress); communication.MediumData.Add("ReplyTo", replyTo); communication.MediumData.Add("Subject", subject); communication.MediumData.Add("HtmlMessage", htmlMessage); communication.MediumData.Add("TextMessage", textMessage); return(communication); } return(null); }
/// <summary> /// Creates the email communication. /// </summary> /// <param name="createEmailCommunicationArgs">The create email communication arguments.</param> /// <returns></returns> public Communication CreateEmailCommunication(CreateEmailCommunicationArgs createEmailCommunicationArgs) { var recipients = createEmailCommunicationArgs.Recipients; var senderPersonAliasId = createEmailCommunicationArgs.SenderPersonAliasId; var fromName = createEmailCommunicationArgs.FromName; var fromAddress = createEmailCommunicationArgs.FromAddress; var replyTo = createEmailCommunicationArgs.ReplyTo; var subject = createEmailCommunicationArgs.Subject; var message = createEmailCommunicationArgs.Message; var bulkCommunication = createEmailCommunicationArgs.BulkCommunication; var sendDateTime = createEmailCommunicationArgs.SendDateTime; var recipientStatus = createEmailCommunicationArgs.RecipientStatus; var systemCommunicationId = createEmailCommunicationArgs.SystemCommunicationId; var recipientsWithPersonIds = recipients.Where(a => a.PersonId.HasValue).Select(a => a.PersonId).ToList(); var recipientEmailsUnknownPersons = recipients.Where(a => a.PersonId == null).Select(a => a.EmailAddress); var recipientPersonList = new PersonService(( RockContext )Context) .Queryable() .Where(p => recipientsWithPersonIds.Contains(p.Id)) .ToList(); if (!recipientPersonList.Any() && recipientEmailsUnknownPersons.Any(a => a != null)) { // For backwards compatibility, if no PersonIds where specified, but there are recipients that are only specified by EmailAddress, take a guess at the personIds by looking for matching email addresses recipientPersonList = new PersonService(( RockContext )Context) .Queryable() .Where(p => recipientEmailsUnknownPersons.Contains(p.Email)) .ToList(); } if (!recipientPersonList.Any()) { return(null); } var communication = new Communication { CommunicationType = CommunicationType.Email, Status = CommunicationStatus.Approved, ReviewedDateTime = RockDateTime.Now, ReviewerPersonAliasId = senderPersonAliasId, SenderPersonAliasId = senderPersonAliasId }; communication.FromName = fromName.TrimForMaxLength(communication, "FromName"); communication.FromEmail = fromAddress.TrimForMaxLength(communication, "FromEmail"); communication.ReplyToEmail = replyTo.TrimForMaxLength(communication, "ReplyToEmail"); communication.Subject = subject.TrimForMaxLength(communication, "Subject"); communication.Message = message; communication.IsBulkCommunication = bulkCommunication; communication.FutureSendDateTime = null; communication.SendDateTime = sendDateTime; communication.SystemCommunicationId = systemCommunicationId; Add(communication); // add each person as a recipient to the communication foreach (var person in recipientPersonList) { var personAliasId = person.PrimaryAliasId; if (!personAliasId.HasValue) { continue; } var communicationRecipient = new CommunicationRecipient { PersonAliasId = personAliasId.Value, Status = recipientStatus, SendDateTime = sendDateTime }; communication.Recipients.Add(communicationRecipient); } return(communication); }