public virtual ActionResult Subscrib(SubscribRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(Views.Subscrib,
                            model));
            }

            var subscription = _subscriptionService.Get(model.Email);

            if (subscription != null)
            {
                if (subscription.IsConfirmed)
                {
                    ModelState.AddModelError("Email",
                                             Resources.Messages_Newsletters_Subscrib_DuplicateEmail);
                    return(View(Views.Subscrib,
                                model));
                }
            }
            else
            {
                subscription = model.To <SubscribRequestModel, Subscription>();

                _subscriptionService.Save(subscription);
            }

            var message = _newslettersMailer.PrepareSubscribConfirmation(subscription);

            _queuedMailService.Save(message,
                                    CurrentConfig.Mails.NoReply.Id);

            subscription.IsPending = true;
            _subscriptionService.Save(subscription);

            SuccessNotification(string.Format(Resources.Messages_Newsletters_Subscrib_ConfirmationEmailSent,
                                              subscription.Email));
            return(RedirectToThen());
        }
Beispiel #2
0
        public static void Save(this IQueuedMailService service,
                                MailMessage message,
                                int accountConfigId)
        {
            var queuedMail = new QueuedMail {
                From     = message.From.Address,
                FromName = message.From.DisplayName,
                To       = message.To[0].Address,
                ToName   = message.To[0].DisplayName,
                Cc       = string.Join(";",
                                       message.CC),
                Bcc = string.Join(";",
                                  message.Bcc),
                Subject         = message.Subject,
                Body            = message.Body,
                IsBodyHtml      = message.IsBodyHtml,
                AccountConfigId = accountConfigId
            };

            service.Save(queuedMail);
        }