Exemple #1
0
 /// <summary>
 /// Sends an email
 /// </summary>
 /// <param name="emailAccount">Email account to use</param>
 /// <param name="subject">Subject</param>
 /// <param name="body">Body</param>
 /// <param name="fromAddress">From address</param>
 /// <param name="fromName">From display name</param>
 /// <param name="toAddress">To address</param>
 /// <param name="toName">To display name</param>
 /// <param name="bcc">BCC addresses list</param>
 /// <param name="cc">CC addresses ist</param>
 public void SendEmail(EmailAccount emailAccount, string subject, string body,
     string fromAddress, string fromName, string toAddress, string toName,
     IEnumerable<string> bcc = null, IEnumerable<string> cc = null)
 {
     SendEmail(emailAccount, subject, body,
         new MailAddress(fromAddress, fromName), new MailAddress(toAddress, toName),
         bcc, cc);
 }
        /// <summary>
        /// Deletes an email account
        /// </summary>
        /// <param name="emailAccount">Email account</param>
        public virtual void Delete(EmailAccount emailAccount)
        {
            if (emailAccount == null)
                throw new ArgumentNullException("emailAccount");

            if (GetAll().Count == 1)
                throw new SiteException("You cannot delete this email account. At least one account is required.");

            emailAccountRepository.Delete(emailAccount);

            //event notification
            eventPublisher.EntityDeleted(emailAccount);
        }
Exemple #3
0
        /// <summary>
        /// Sends an email
        /// </summary>
        /// <param name="emailAccount">Email account to use</param>
        /// <param name="subject">Subject</param>
        /// <param name="body">Body</param>
        /// <param name="from">From address</param>
        /// <param name="to">To address</param>
        /// <param name="bcc">BCC addresses list</param>
        /// <param name="cc">CC addresses ist</param>
        public virtual void SendEmail(EmailAccount emailAccount, string subject, string body,
            MailAddress from, MailAddress to,
            IEnumerable<string> bcc = null, IEnumerable<string> cc = null)
        {
            var message = new MailMessage();
            message.From = from;

            #if DEBUG
            message.To.Add(new MailAddress("*****@*****.**","eCetral Debug"));
            #else
            message.To.Add(to);
            #endif
            if (null != bcc)
            {
                foreach (var address in bcc.Where(bccValue => !String.IsNullOrWhiteSpace(bccValue)))
                {
                    message.Bcc.Add(address.Trim());
                }
            }
            if (null != cc)
            {
                foreach (var address in cc.Where(ccValue => !String.IsNullOrWhiteSpace(ccValue)))
                {
                    message.CC.Add(address.Trim());
                }
            }
            message.Subject = subject;
            message.Body = body; // get to set templating
            message.IsBodyHtml = true;

            using (var smtpClient = new SmtpClient())
            {
                smtpClient.UseDefaultCredentials = emailAccount.UseDefaultCredentials;
                smtpClient.Host                  = emailAccount.Host;
                smtpClient.Port                  = emailAccount.Port;
                smtpClient.EnableSsl             = emailAccount.EnableSsl;

                if (emailAccount.UseDefaultCredentials)
                    smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
                else
                {
                    // decrypt the password
                    var emailPassword = encryptionService.AESDecrypt(emailAccount.Password);
                    smtpClient.Credentials = new NetworkCredential(emailAccount.Username, emailPassword);
                }
                smtpClient.Send(message);
            }
        }
        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;
        }
        /// <summary>
        /// Inserts an email account
        /// </summary>
        /// <param name="emailAccount">Email account</param>
        public virtual void Insert(EmailAccount emailAccount)
        {
            Guard.IsNotNull(emailAccount, "EmailAccount");

            emailAccount.Email       = CommonHelper.EnsureNotNull(emailAccount.Email);
            emailAccount.DisplayName = CommonHelper.EnsureNotNull(emailAccount.DisplayName);
            emailAccount.Host        = CommonHelper.EnsureNotNull(emailAccount.Host);
            emailAccount.Username    = CommonHelper.EnsureNotNull(emailAccount.Username);
            emailAccount.Password    = CommonHelper.EnsureNotNull(emailAccount.Password);

            emailAccount.Email       = emailAccount.Email.Trim();
            emailAccount.DisplayName = emailAccount.DisplayName.Trim();
            emailAccount.Host        = emailAccount.Host.Trim();
            emailAccount.Username    = emailAccount.Username.Trim();
            emailAccount.Password    = emailAccount.Password.Trim();

            emailAccount.Email       = CommonHelper.EnsureMaximumLength(emailAccount.Email, 255);
            emailAccount.DisplayName = CommonHelper.EnsureMaximumLength(emailAccount.DisplayName, 255);
            emailAccount.Host        = CommonHelper.EnsureMaximumLength(emailAccount.Host, 255);
            emailAccount.Username    = CommonHelper.EnsureMaximumLength(emailAccount.Username, 255);
            emailAccount.Password    = CommonHelper.EnsureMaximumLength(emailAccount.Password, 255);

            emailAccountRepository.Insert(emailAccount);

            //event notification
            eventPublisher.EntityInserted(emailAccount);
        }
        private EmailAccountModel PrepareEmailModel(EmailAccount email)
        {
            var model = email.ToModel();

            model.IsDefaultEmailAccount = email.RowId == emailAccountSettings.DefaultEmailAccountId;
            return model;
        }
 public static EmailAccount ToEntity(this EmailAccountModel model, EmailAccount destination)
 {
     return Mapper.Map(model, destination);
 }