예제 #1
0
        public MailMessage CampaignEmailBlast(CampaignEmailBlastModel model)
        {
            var mailMessage = new MailMessage
                                  {
                                      Subject = string.Format("{0} {1} would like you to take a gander at '{2}'",
                                          model.FirstName, model.LastName, model.Title),
                                      From = new MailAddress(model.Email, string.Format("{0} {1}",
                                          model.FirstName, model.LastName))
                                  };

            var emails = model.EmailAddresses.Split(new[] { ',', ';' });

            foreach (var email in emails.Where(email => !string.IsNullOrWhiteSpace(email)))
            {
                mailMessage.To.Add(email.Trim());
            }

            ViewData = new ViewDataDictionary(model);
            PopulateBody(mailMessage, viewName: "CampaignEmailBlast");
            return mailMessage;
        }
예제 #2
0
        public ActionResult SendEmail(CampaignEmailBlastModel model)
        {
            using (campaignRepository)
            {
                var campaign = campaignRepository.GetCampaignByUrlSlug(model.UrlSlug);

                if (campaign != null)
                {
                    var userProfile = campaign.UserProfile;

                    // Only allow email to send if the campaign owner is currently logged in
                    if (User.Identity.Name.Equals(userProfile.Email, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (ModelState.IsValid)
                        {
                            model.Url = Url.ToPublicUrl(Url.Action("Index", "Campaign", new { slug = model.UrlSlug }));
                            campaignMailer.CampaignEmailBlast(model).SendAsync();
                            return Json(new { success = "true" });
                        }
                    }
                    else
                    {
                        // If not, return 403 status code
                        Response.StatusCode = (int) HttpStatusCode.Forbidden;
                    }
                }
            }

            return Json(new { success = "false" });
        }