Ejemplo n.º 1
0
        public void SendMail(List <NewsletterRegistration> emails, string mailtext, string subject /*, string pathtoattachment*/)
        {
            // Set up mail credentials
            MailAddress mailFrom = new MailAddress("*****@*****.**");

            // Configure the SMTP client
            SmtpClient smtp = new SmtpClient();

            smtp.Port                  = 587; // 465 might also work, in case 587 wont
            smtp.EnableSsl             = true;
            smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials           = new NetworkCredential("*****@*****.**", "avansb4!");
            smtp.Host                  = "smtp.gmail.com";

            // Create the mail for each recipient and send it
            for (int i = 0; i < emails.Count; i++)
            {
                NewsletterRegistration m = emails[i];

                MailAddress mailTo = new MailAddress(m.Email);
                MailMessage mm     = new MailMessage(mailFrom, mailTo);
                mm.Body = "Beste " + m.Name + ",<br /><br />" + mailtext +
                          "<br /><br />Met vriendelijke groet, <br/> Avans Bioscopen";
                mm.IsBodyHtml = true;
                mm.Subject    = subject;
                //mm.Attachments.Add(new Attachment(pathtoattachment));
                smtp.Send(mm);
            }
        }
Ejemplo n.º 2
0
        public ActionResult NewsletterUnsubscribe(string email, string guid)
        {
            email = HttpUtility.UrlDecode(email);
            guid  = HttpUtility.UrlDecode(guid);

            using (var db = new SiteDbContext())
            {
                var ifEmailExist = db.NewsletterRegistration
                                   .Any(r => r.Email.Equals(email));

                if (ifEmailExist)
                {
                    var userData = db.NewsletterRegistration.Where(r => r.Email.Equals(email)).FirstOrDefault();
                    if (userData.Email == email && userData.SecretKey == guid)
                    {
                        NewsletterRegistration newsletterAccount = db.NewsletterRegistration.Find(userData.Id);
                        db.Entry(newsletterAccount).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();

                        ViewBag.Message = "Vous êtes maintenant désinscrit de la newsletter de Gamers Addict.";
                    }
                    else
                    {
                        ViewBag.Message = "Erreur dans clef secrète.";
                    }
                }
                else
                {
                    ViewBag.Message = "Vous n'êtes pas inscrit à la newsletter, désinscription impossible.";
                }
            }
            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult NewsletterSubscribe(NewsletterRegistration model)
        {
            using (var db = new SiteDbContext())
            {
                var ifEmailExist = db.NewsletterRegistration
                                   .Any(r => r.Email.Equals(model.Email));

                if (!ifEmailExist)
                {
                    NewsletterRegistration newRegistration = new NewsletterRegistration
                    {
                        Email     = model.Email,
                        SecretKey = Guid.NewGuid().ToString()
                    };

                    db.NewsletterRegistration.Add(newRegistration);
                    db.SaveChanges();

                    return(Json("Inscription effectuée !", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json("L'adresse email est déjà inscrite !", JsonRequestBehavior.AllowGet));
                }
            }
        }
        public ActionResult ChangeEmail(ChangeEmailViewModel model)
        {
            if (ModelState.IsValid)
            {
                //Update Account
                var context = HttpContext.GetOwinContext().Get <ApplicationDbContext>();
                ApplicationUserManager _userManager = new ApplicationUserManager(new Microsoft.AspNet.Identity.EntityFramework.UserStore <ApplicationUser>(context));
                var user = _userManager.FindByName(User.Identity.Name);

                var oldEmail = user.Email;
                user.Email = model.Email;
                _userManager.Update(user);
                HttpContext.GetOwinContext().Get <ApplicationDbContext>().SaveChanges();

                //Update Newsletter
                using (var db = new SiteDbContext())
                {
                    var ifEmailExist = db.NewsletterRegistration
                                       .Any(r => r.Email.Equals(oldEmail));

                    if (ifEmailExist)
                    {
                        NewsletterRegistration newsletterRegistration = db.NewsletterRegistration
                                                                        .Where(r => r.Email == oldEmail)
                                                                        .Select(r => r).FirstOrDefault();

                        newsletterRegistration.Email = model.Email;

                        db.Entry(newsletterRegistration).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                }

                //Update YouTube Alert
                using (var db = new SiteDbContext())
                {
                    var ifEmailExist = db.YouTubeAlertRegistration
                                       .Any(r => r.Email.Equals(oldEmail));

                    if (ifEmailExist)
                    {
                        YouTubeAlertRegistration youTubeAlertRegistration = db.YouTubeAlertRegistration
                                                                            .Where(r => r.Email == oldEmail)
                                                                            .Select(r => r).FirstOrDefault();

                        youTubeAlertRegistration.Email = model.Email;

                        db.Entry(youTubeAlertRegistration).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index", new { Message = "Adresse Email modifier avec succès !" }));
            }

            return(View(model));
        }
        public ActionResult HandleFormSubmit(NewsletterRegistration model)
        {
            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());
            }

            MailMessage message = new MailMessage();

            message.To.Add("*****@*****.**");
            //message.Bcc.Add("*****@*****.**");
            message.Bcc.Add("*****@*****.**");
            message.Subject = "thethirdtestament.info: Newsletter registration";
            message.From    = new MailAddress(model.Email, model.Firstname + " " + model.Lastname);
            message.Body    = model.Firstname + " " + model.Lastname + ": " + model.Email;

            using (SmtpClient smtp = new SmtpClient())
            {
                smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                smtp.UseDefaultCredentials = false;
                smtp.EnableSsl             = true;
                smtp.Host        = "smtp.gmail.com";
                smtp.Port        = 587;
                smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "yapxnkiyjdmgskcj");
                smtp.EnableSsl   = true;

                // send mail
                smtp.Send(message);
                TempData["success"] = true;
            }

            IContent msg = Services.ContentService.CreateContent(model.Firstname + " " + model.Lastname, CurrentPage.Id, "newsletterRegistration");

            msg.SetValue("firstname", model.Firstname);
            msg.SetValue("lastname", model.Lastname);
            msg.SetValue("email", model.Email);

            Services.ContentService.Save(msg);

            return(RedirectToCurrentUmbracoPage());
        }
        //
        // GET: /Manage/ChangeNewsletter
        public ActionResult ChangeNewsletter()
        {
            using (var db = new SiteDbContext())
            {
                //Get Username
                var pseudo = User.Identity.GetUserName();

                //Get Email
                var applicationDbContext = HttpContext.GetOwinContext().Get <ApplicationDbContext>();
                var email = applicationDbContext.Users
                            .Where(r => r.UserName == pseudo)
                            .Select(r => r.Email).ToArray()[0];

                ViewBag.email = email;

                //Verify if is register
                var ifEmailExist = db.NewsletterRegistration
                                   .Any(r => r.Email.Equals(email));

                if (ifEmailExist)
                {
                    var userData = db.NewsletterRegistration.Where(r => r.Email.Equals(email)).FirstOrDefault();
                    ViewBag.register  = "true";
                    ViewBag.secretKey = userData.SecretKey;

                    return(View());
                }
                else
                {
                    ViewBag.register = "false";
                    NewsletterRegistration newsletterModel = new NewsletterRegistration();
                    newsletterModel.Email = email;

                    return(View(newsletterModel));
                }
            }
        }