/// <summary> /// Adds the recipient. /// </summary> /// <param name="messageRecipient">The message recipient.</param> public void AddRecipient(RockMessageRecipient messageRecipient) { this.Recipients.Add(messageRecipient); }
private RockEmailMessage GetRecipientRockEmailMessage(RockEmailMessage emailMessage, RockMessageRecipient rockMessageRecipient, Dictionary <string, object> mergeFields, string organizationEmail) { var recipientEmail = new RockEmailMessage(); recipientEmail.CurrentPerson = emailMessage.CurrentPerson; recipientEmail.EnabledLavaCommands = emailMessage.EnabledLavaCommands; recipientEmail.AppRoot = emailMessage.AppRoot; recipientEmail.CssInliningEnabled = emailMessage.CssInliningEnabled; // CC recipientEmail.CCEmails = emailMessage.CCEmails; // BCC recipientEmail.BCCEmails = emailMessage.BCCEmails; // Attachments recipientEmail.Attachments = emailMessage.Attachments; // Communication record for tracking opens & clicks recipientEmail.MessageMetaData = new Dictionary <string, string>(emailMessage.MessageMetaData); foreach (var mergeField in mergeFields) { rockMessageRecipient.MergeFields.AddOrIgnore(mergeField.Key, mergeField.Value); } // To var toEmailAddress = new RockEmailMessageRecipient(null, null) { To = rockMessageRecipient .To .ResolveMergeFields(rockMessageRecipient.MergeFields, emailMessage.CurrentPerson, emailMessage.EnabledLavaCommands), Name = rockMessageRecipient .Name .ResolveMergeFields(rockMessageRecipient.MergeFields, emailMessage.CurrentPerson, emailMessage.EnabledLavaCommands) }; recipientEmail.SetRecipients(new List <RockEmailMessageRecipient> { toEmailAddress }); var fromMailAddress = new MailAddress(emailMessage.FromEmail, emailMessage.FromName); var checkResult = CheckSafeSender(new List <string> { toEmailAddress.EmailAddress }, fromMailAddress, organizationEmail); // Reply To recipientEmail.ReplyToEmail = GetRecipientReplyToAddress(emailMessage, mergeFields, checkResult); // From if (checkResult.IsUnsafeDomain && checkResult.SafeFromAddress != null) { recipientEmail.FromName = checkResult.SafeFromAddress.DisplayName; recipientEmail.FromEmail = checkResult.SafeFromAddress.Address; } else { recipientEmail.FromName = fromMailAddress.DisplayName; recipientEmail.FromEmail = fromMailAddress.Address; } // Subject string subject = ResolveText(emailMessage.Subject, emailMessage.CurrentPerson, emailMessage.EnabledLavaCommands, rockMessageRecipient.MergeFields, emailMessage.AppRoot, emailMessage.ThemeRoot).Left(998); recipientEmail.Subject = subject; // Plain Text Message recipientEmail.PlainTextMessage = ResolveText(emailMessage.PlainTextMessage, emailMessage.CurrentPerson, emailMessage.EnabledLavaCommands, rockMessageRecipient.MergeFields, emailMessage.AppRoot, emailMessage.ThemeRoot); // Body (HTML) string body = ResolveText(emailMessage.Message, emailMessage.CurrentPerson, emailMessage.EnabledLavaCommands, rockMessageRecipient.MergeFields, emailMessage.AppRoot, emailMessage.ThemeRoot); body = Regex.Replace(body, @"\[\[\s*UnsubscribeOption\s*\]\]", string.Empty); recipientEmail.Message = body; Guid?recipientGuid = null; recipientEmail.CreateCommunicationRecord = emailMessage.CreateCommunicationRecord; if (emailMessage.CreateCommunicationRecord) { recipientGuid = Guid.NewGuid(); recipientEmail.MessageMetaData["communication_recipient_guid"] = recipientGuid.ToString(); } return(recipientEmail); }