Exemple #1
0
        private static MailMessage BuildMailMessage(QueuedMessage queuedMessage)
        {
            var mailMessage = new MailMessage()
            {
                From = new MailAddress(queuedMessage.FromAddress, queuedMessage.FromName),
                Subject = queuedMessage.Subject,
                Body = queuedMessage.Body
            };
            var multipleToAddress = queuedMessage.ToAddress.Split(new char[] { ',',';' }, StringSplitOptions.RemoveEmptyEntries);
            if (multipleToAddress.Any()){
                foreach (var email in multipleToAddress)
                {
                    mailMessage.To.Add(new MailAddress(email.Trim(), queuedMessage.ToName));
                }
            }

            if (!string.IsNullOrWhiteSpace(queuedMessage.Cc))
                mailMessage.CC.Add(queuedMessage.Cc);
            if (!string.IsNullOrWhiteSpace(queuedMessage.Bcc))
                mailMessage.Bcc.Add(queuedMessage.Bcc);

            if (queuedMessage.QueuedMessageAttachments != null)
                foreach (QueuedMessageAttachment attachment in queuedMessage.QueuedMessageAttachments)
                    mailMessage.Attachments.Add(new Attachment(attachment.FileName));

            mailMessage.IsBodyHtml = queuedMessage.IsHtml;
            return mailMessage;
        }
        public void ResetPasswordService_SetResetPassword_ShouldSaveAQueuedMessage()
        {
            var user = new User();
            var queuedMessage = new QueuedMessage();
            A.CallTo(() => _messageParser.GetMessage(user, null, null, null, null, null, null))
             .Returns(queuedMessage);

            _resetPasswordService.SetResetPassword(user);

            A.CallTo(() => _messageParser.QueueMessage(queuedMessage, true)).MustHaveHappened();
        }
Exemple #3
0
        public void SendMailMessage(QueuedMessage queuedMessage)
        {
            try
            {
                var mailMessage = BuildMailMessage(queuedMessage);

                _smtpClient.Send(mailMessage);
                queuedMessage.SentOn = CurrentRequestData.Now;
            }
            catch (Exception exception)
            {
                // TODO: Make this work without HTTP context
                CurrentRequestData.ErrorSignal.Raise(exception);
                queuedMessage.Tries++;
            }
            _session.Transact(session => session.SaveOrUpdate(queuedMessage));
        }
 public ActionResult Show(QueuedMessage queuedMessage)
 {
     return View(queuedMessage);
 }
Exemple #5
0
 public bool CanSend(QueuedMessage queuedMessage)
 {
     return !string.IsNullOrEmpty(queuedMessage.ToAddress) && _smtpClient.Credentials != null &&
            !string.IsNullOrWhiteSpace(_smtpClient.Host) && _siteSettings.SiteIsLive;
 }
Exemple #6
0
 public void AddToQueue(QueuedMessage queuedMessage)
 {
     _session.Transact(session => session.SaveOrUpdate(queuedMessage));
 }