예제 #1
0
 public void AddRecipient(string to)
 {
     if (to.IsNotNullOrWhiteSpace())
     {
         Recipients.Add(RockEmailMessageRecipient.CreateAnonymous(to, null));
     }
 }
예제 #2
0
 public void SetRecipients(List <RecipientData> recipientData)
 {
     this.Recipients = new List <RockMessageRecipient>();
     foreach (var recipient in recipientData)
     {
         // assume it is an email recipient
         this.AddRecipient(RockEmailMessageRecipient.CreateAnonymous(recipient.To, recipient.MergeFields));
     }
 }
예제 #3
0
 private void InitEmailMessage(SystemEmail systemEmail)
 {
     if (systemEmail != null)
     {
         this.FromEmail = systemEmail.From;
         this.FromName  = systemEmail.FromName;
         var recipients = systemEmail.To.SplitDelimitedValues().ToList().Select(a => RockEmailMessageRecipient.CreateAnonymous(a, null)).ToList();
         this.SetRecipients(recipients);
         this.CCEmails  = systemEmail.Cc.SplitDelimitedValues().ToList();
         this.BCCEmails = systemEmail.Bcc.SplitDelimitedValues().ToList();
         this.Subject   = systemEmail.Subject;
         this.Message   = systemEmail.Body;
     }
 }
예제 #4
0
        /// <summary>
        /// Initializes the email message.
        /// </summary>
        /// <param name="systemCommunication">The system email.</param>
        private void InitEmailMessage(SystemCommunication systemCommunication)
        {
            if (systemCommunication == null)
            {
                return;
            }

            this.FromEmail = systemCommunication.From;
            this.FromName  = systemCommunication.FromName;

            var recipients = systemCommunication.To.SplitDelimitedValues().ToList().Select(a => RockEmailMessageRecipient.CreateAnonymous(a, null)).ToList();

            this.SetRecipients(recipients);

            this.CCEmails              = systemCommunication.Cc.SplitDelimitedValues().ToList();
            this.BCCEmails             = systemCommunication.Bcc.SplitDelimitedValues().ToList();
            this.Subject               = systemCommunication.Subject;
            this.Message               = systemCommunication.Body;
            this.CssInliningEnabled    = systemCommunication.CssInliningEnabled;
            this.SystemCommunicationId = systemCommunication.Id;
        }
예제 #5
0
 public void SetRecipients(List <string> toEmails)
 {
     Recipients.AddRange(toEmails.Select(a => RockEmailMessageRecipient.CreateAnonymous(a, null)));
 }
예제 #6
0
 public void SetRecipients(string toEmails)
 {
     Recipients.AddRange(toEmails.SplitDelimitedValues().ToList().Select(a => RockEmailMessageRecipient.CreateAnonymous(a, null)));
 }
예제 #7
0
 public void AddRecipient(RecipientData recipient)
 {
     Recipients.Add(RockEmailMessageRecipient.CreateAnonymous(recipient.To, recipient.MergeFields));
 }
예제 #8
0
        private RockEmailMessage GetRecipientRockEmailMessage(RockEmailMessage emailMessage, Model.Communication communication, CommunicationRecipient communicationRecipient, Dictionary <string, object> mergeFields, string organizationEmail, Dictionary <string, string> mediumAttributes)
        {
            var recipientEmail = new RockEmailMessage();

            recipientEmail.CurrentPerson       = emailMessage.CurrentPerson;
            recipientEmail.EnabledLavaCommands = emailMessage.EnabledLavaCommands;
            recipientEmail.AppRoot             = emailMessage.AppRoot;
            recipientEmail.CssInliningEnabled  = emailMessage.CssInliningEnabled;

            // CC
            if (communication.CCEmails.IsNotNullOrWhiteSpace())
            {
                string[] ccRecipients = communication
                                        .CCEmails
                                        .ResolveMergeFields(mergeFields, emailMessage.CurrentPerson)
                                        .Replace(";", ",")
                                        .Split(',');

                foreach (var ccRecipient in ccRecipients)
                {
                    recipientEmail.CCEmails.Add(ccRecipient);
                }
            }

            // BCC
            if (communication.BCCEmails.IsNotNullOrWhiteSpace())
            {
                string[] bccRecipients = communication
                                         .BCCEmails
                                         .ResolveMergeFields(mergeFields, emailMessage.CurrentPerson)
                                         .Replace(";", ",")
                                         .Split(',');

                foreach (var bccRecipient in bccRecipients)
                {
                    recipientEmail.BCCEmails.Add(bccRecipient);
                }
            }

            // Attachments
            recipientEmail.Attachments = emailMessage.Attachments;

            // Communication record for tracking opens & clicks
            recipientEmail.MessageMetaData = new Dictionary <string, string>(emailMessage.MessageMetaData);

            // To
            var toEmailAddress = new RockEmailMessageRecipient(null, null)
            {
                To   = communicationRecipient.PersonAlias.Person.Email,
                Name = communicationRecipient.PersonAlias.Person.FullName
            };

            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
            var subject = ResolveText(communication.Subject, emailMessage.CurrentPerson, communication.EnabledLavaCommands, mergeFields, emailMessage.AppRoot);

            recipientEmail.Subject = subject;

            // Body Plain Text
            if (mediumAttributes.ContainsKey("DefaultPlainText"))
            {
                var plainText = ResolveText(mediumAttributes["DefaultPlainText"],
                                            emailMessage.CurrentPerson,
                                            communication.EnabledLavaCommands,
                                            mergeFields,
                                            emailMessage.AppRoot);

                if (!string.IsNullOrWhiteSpace(plainText))
                {
                    recipientEmail.PlainTextMessage = plainText;
                }
            }

            // Body (HTML)
            string htmlBody = communication.Message;

            // Get the unsubscribe content and add a merge field for it
            if (communication.IsBulkCommunication && mediumAttributes.ContainsKey("UnsubscribeHTML"))
            {
                string unsubscribeHtml = ResolveText(mediumAttributes["UnsubscribeHTML"],
                                                     emailMessage.CurrentPerson,
                                                     communication.EnabledLavaCommands,
                                                     mergeFields,
                                                     emailMessage.AppRoot);

                mergeFields.AddOrReplace("UnsubscribeOption", unsubscribeHtml);

                htmlBody = ResolveText(htmlBody, emailMessage.CurrentPerson, communication.EnabledLavaCommands, mergeFields, emailMessage.AppRoot);

                // Resolve special syntax needed if option was included in global attribute
                if (Regex.IsMatch(htmlBody, @"\[\[\s*UnsubscribeOption\s*\]\]"))
                {
                    htmlBody = Regex.Replace(htmlBody, @"\[\[\s*UnsubscribeOption\s*\]\]", unsubscribeHtml);
                }

                // Add the unsubscribe option at end if it wasn't included in content
                if (!htmlBody.Contains(unsubscribeHtml))
                {
                    htmlBody += unsubscribeHtml;
                }
            }
            else
            {
                htmlBody = ResolveText(htmlBody, emailMessage.CurrentPerson, communication.EnabledLavaCommands, mergeFields, emailMessage.AppRoot);
                htmlBody = Regex.Replace(htmlBody, @"\[\[\s*UnsubscribeOption\s*\]\]", string.Empty);
            }

            if (!string.IsNullOrWhiteSpace(htmlBody))
            {
                if (emailMessage.CssInliningEnabled)
                {
                    // move styles inline to help it be compatible with more email clients
                    htmlBody = htmlBody.ConvertHtmlStylesToInlineAttributes();
                }

                // add the main Html content to the email
                recipientEmail.Message = htmlBody;
            }

            recipientEmail.MessageMetaData["communication_recipient_guid"] = communicationRecipient.Guid.ToString();

            return(recipientEmail);
        }
예제 #9
0
        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);
        }