Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. public ActionResult SendMails()
  2. {
  3. AccountVM acc = new AccountVM();
  4. BorrowingVM bor = new BorrowingVM();
  5. BookVM book = new BookVM();
  6.  
  7. var emails = from b in book.Get_list()
  8. from o in bor.Get_list()
  9. from a in acc.Get_list()
  10. where o.BookID==b.BookID && a.AccountID==o.ReaderID && o.Returned==false && o.Return_date < DateTime.Now
  11. select new
  12. {
  13. a.Email,
  14. b.Title
  15. };
  16.  
  17. GMailer.GmailUsername = "panmail1212p@gmail.com";
  18. GMailer.GmailPassword = "zaq1@wsx";
  19. GMailer mailer = new GMailer();
  20. foreach (var e in emails)
  21. {
  22. mailer.ToEmail = e.Email;
  23. mailer.Subject = "BIBLIOTEKA - Zwrot książki";
  24. mailer.Body = "Prosimy o zwrot książki '" + e.Title + "' !";
  25. mailer.IsHtml = true;
  26. mailer.Send();
  27. }
  28. ViewBag.Mails1 = "Wysłano próśb " + emails.Count();
  29.  
  30. var emails1 = from b in book.Get_list()
  31. from o in bor.Get_list()
  32. from a in acc.Get_list()
  33. where o.BookID == b.BookID && a.AccountID == o.ReaderID && o.Returned == false && o.Return_date.Date == DateTime.Now.Date.AddDays(1)
  34. select new
  35. {
  36. a.Email,
  37. b.Title
  38. };
  39.  
  40. foreach (var e in emails1)
  41. {
  42. mailer.ToEmail = e.Email;
  43. mailer.Subject = "BIBLIOTEKA - Przypomnienie o zwrocie książki!";
  44. mailer.Body = "Został jeden dzień do zwrotu książki '" + e.Title + "' ! Po upływie czasu kara zastanie naliczona!";
  45. mailer.IsHtml = true;
  46. mailer.Send();
  47. }
  48.  
  49. ViewBag.Mails2 = "Wysłano przypomnień " + emails1.Count();
  50. return View("Admin");
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement