public ActionResult index(FollowEmailDO objModelMail) { using (var db = new ProjectWebEntities()) { try { if (ModelState.IsValid) { var mBody = "<p style=\"font: 700 14px bold;\">Nội dung: </p>" + HttpUtility.HtmlDecode(objModelMail.Content) + "<br/>" + HttpUtility.HtmlDecode(objModelMail.Signature); var mail = new ConfigMail() { Subject = objModelMail.subject, Body = mBody, }; var fromMailAddress = new MailAddress(db.Tbl_AboutUs.Single(p => p.Id == 1).EmailSent); string mailPassword = db.Tbl_AboutUs.Single(p => p.Id == 1).EmailPassword; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromMailAddress.Address, mailPassword) }; foreach (var m in db.Tbl_FollowEmail.Where(p => p.IsDisable == GlobalVariables.status_Normal)) { var body2 = " " + "<a href=" + GlobalVariables.WebRoot + "FollowEmail/unFollow/" + m.Code + "style='color:#ccc'>" + "Ngừng nhận email thông báo.<br/>" + "</a>"; using (var messageBody = new MailMessage() { From = fromMailAddress, Subject = mail.Subject, IsBodyHtml = true, Body = mail.Body + body2, }) { messageBody.Bcc.Add(m.Email); smtp.Send(messageBody); } } } } catch (Exception ex) { _logger.Error("An Error Happened! ", ex); } return(RedirectToAction("index", "FollowEmail")); } }
private static IEnumerable <FollowEmailDO> getFollowEmail() { using (var db = new ProjectWebEntities()) { var result = new List <FollowEmailDO>(); foreach (var m in db.Tbl_FollowEmail) { var tmp = new FollowEmailDO(); tmp.Id = m.Id; tmp.Email = m.Email; if (m.IsDisable == GlobalVariables.status_Normal) { tmp.IsDisable = "Hoạt động"; } else { tmp.IsDisable = "Không hoạt động"; } result.Add(tmp); } return(result); } }