public IActionResult PostEmailRegistration(EmailRegistration emailRegistration)
        {
            var    email = emailRegRepository.GetAll().Where(p => p.EmailAddress == emailRegistration.EmailAddress).ToList();
            string postResultString;
            int    messageNumber;

            if (!email.Any())
            {
                emailRegistration.ControlCode = Guid.NewGuid().ToString();
                emailRegistration.CreateTime  = DateTime.Now;
                if (emailRegRepository.AddEmailReg(emailRegistration))
                {
                    postResultString = "E-posta listemize kaydedildiniz. Teşekkür ederiz.";
                    messageNumber    = 2;
                }
                else
                {
                    postResultString = "E-posta kaydı yapılırken bir hata oluştu! Lütfen daha sonra tekrar deneyiniz.";
                    messageNumber    = 3;
                }
            }
            else
            {
                postResultString = "Bu e-posta adresi zaten kayıtlı!";
                messageNumber    = 1;
            }

            return(new JsonResult(new { message = postResultString, messageType = messageNumber }));
        }
 public IActionResult Index()
 {
     if (TempData["EmailRegDeleteSuccess"] != null)
     {
         ViewBag.EmailRegDeleteSuccess = TempData["EmailRegDeleteSuccess"];
     }
     if (TempData["EmailRegDeleteError"] != null)
     {
         ViewBag.EmailRegDeleteError = TempData["EmailRegDeleteError"];
     }
     return(View(emailRegRepository.GetAll().OrderByDescending(p => p.CreateTime).ToList()));
 }
Exemple #3
0
        public IActionResult BlogNotificationMailSend(int id)
        {
            try
            {
                var    setting     = settingRepository.GetById(1);
                var    emailList   = emailRegRepository.GetAll().Select(p => p.EmailAddress).ToList();
                var    blog        = blogRepository.GetById(id);
                string messageHtml = "" +
                                     "<div style='background-color:#F7F7F7;padding:5px;'>" +
                                     "<div style='background-color:#FFF;padding:5px;'>" +
                                     "<h3 style='text-align:center'>" + blog.Title + "</h3>" +
                                     "<p style='text-align:center'><img src='https://" + setting.SiteName + "/img/" + blog.ImageUrl + "' width='400px'/></p>" +
                                     "<p style='text-align:justify'>" + blog.Explanation + "...</p>" +
                                     "<a href='https://" + setting.SiteName + "/Home/Detail/" + blog.BlogId + "' style='text-decoration:none;text-align:center;display:block; background-color:#007bff;color:#fff;padding:10px 15px;border-radius:15px'>Makeleye Git</a>" +
                                     "<hr/>" +
                                     "<p>E-Posta aboneliğimizden çıkmak için <a href='https://" + setting.SiteName + "/Home/EmailCancellation'>buraya tıklayarak</a> ilgili adrese gidiniz.</p>" +
                                     "</div>" +
                                     "</div>";

                MailBuilder builder = new MailBuilder();

                builder.From.Add(new MailBox(setting.SMTPServerFrom, setting.SMTPServerFromName));
                builder.To.Add(new MailGroup("Undisclosed recipients"));

                foreach (string item in emailList)
                {
                    builder.Bcc.Add(new MailBox(item));
                }

                builder.Subject = blog.Title;
                builder.Html    = messageHtml;

                IMail email = builder.Create();

                using Smtp smtp = new Smtp();
                smtp.Connect(setting.SMTPServerHost, Convert.ToInt32(setting.SMTPServerPort)); // or ConnectSSL for SSL
                smtp.UseBestLogin(setting.SMTPServerUsername, setting.SMTPServerPassword);     // remove if not needed
                smtp.SendMessage(email);
                smtp.Close();

                blog.IsMailSend = true;
                if (blogRepository.UpdateBlog(blog))
                {
                    TempData["MailNotificationSuccess"] = "'" + blog.Title + "', bloğu için e-posta bildirimleri gönderildi.";
                }
            }
            catch
            {
                TempData["MailNotificationDanger"] = "E-Posta bildirimi gönderilirken bir hata oluştu!";
            }

            return(RedirectToAction("List"));
        }