Пример #1
0
        private Guid SendNotification(MessageTemplate messageTemplate,
            EmailAccount emailAccount, Guid languageId, IEnumerable<Token> tokens,
            string toEmailAddress, string toName)
        {
            //retrieve localized message template data
            var bcc     = messageTemplate.GetLocalized((mt) => mt.BccEmailAddresses, languageId);
            var subject = messageTemplate.GetLocalized((mt) => mt.Subject, languageId);
            var body    = messageTemplate.GetLocalized((mt) => mt.Body, languageId);

            //Replace subject and body tokens
            var subjectReplaced = tokenizer.Replace(subject, tokens, false);
            var bodyReplaced    = tokenizer.Replace(body, tokens, true);

            // retrieve the main localized master template
            var masterTemplate = GetLocalizedActiveMessageTemplate("Templates.Master", languageId);
            if (masterTemplate != null)
            {
                // set master template tokens
                var masterBody = masterTemplate.GetLocalized((mt) => mt.Body, languageId);
                messageTokenProvider.AddMasterTokens((IList<Token>)tokens, bodyReplaced);
                bodyReplaced = tokenizer.Replace(masterBody, tokens, true);
            }

            var email = new QueuedEmail()
            {
                Priority       = 5,
                From           = emailAccount.Email,
                FromName       = emailAccount.DisplayName,
                To             = toEmailAddress,
                ToName         = toName,
                CC             = string.Empty,
                Bcc            = bcc,
                Subject        = subjectReplaced,
                Body           = bodyReplaced,
                CreatedOn      = DateTime.UtcNow,
                EmailAccountId = emailAccount.RowId
            };

            queuedEmailService.Insert(email);
            return email.RowId;
        }
Пример #2
0
 private EmailAccount GetEmailAccountOfMessageTemplate(MessageTemplate messageTemplate, Guid languageId)
 {
     var emailAccounId = messageTemplate.GetLocalized(mt => mt.EmailAccountId, languageId);
     var emailAccount  = emailAccountService.GetById(emailAccounId);
     if (emailAccount  == null)
         emailAccount  = emailAccountService.GetById(emailAccountSettings.DefaultEmailAccountId);
     if (emailAccount  == null)
         emailAccount  = emailAccountService.GetAll().FirstOrDefault();
     return emailAccount;
 }