Advertisement
Guest User

Untitled

a guest
Jan 14th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. @using SendEmail.Models @model List
  2. <user>
  3.  
  4. @{ Layout = "~/Views/Shared/_Layout.cshtml"; }
  5.  
  6. <h2>@ViewBag.ButtonText</h2>
  7.  
  8.  
  9. <script type="text/javascript" src="@Url.Content(" ~/Scripts/ ")jquery-1.10.2.js"></script>
  10. <script type="text/javascript">
  11. $(document).ready(function() {
  12. $('#checkBoxAll').click(function() {
  13. if ($(this).is(":checked"))
  14. $('.chkCheckBoxId').prop('checked', true);
  15. else
  16. $('.chkCheckBoxId').prop('checked', false);
  17.  
  18. });
  19. });
  20. </script>
  21.  
  22. @if (ViewBag.ButtonText == "Send Reminder Email") {
  23. @using (Html.BeginForm("SendReminder", "ControllerName", FormMethod.Post))
  24. {
  25. <table>
  26. <tr>
  27.  
  28. <th>First Name</th>
  29. <th>Last Name</th>
  30. <th>Email</th>
  31. <th>
  32. <input type="checkbox" id="checkBoxAll" />Select All</th>
  33.  
  34. </tr>
  35. @foreach (user u in Model) {
  36. <tr>
  37.  
  38. <td>@u.first_name</td>
  39. <td>@u.last_name</td>
  40. <td>@u.email</td>
  41. <td>
  42. <input type="checkbox" class="chkCheckBoxId" value="@u.email" name="userId" />
  43.  
  44. </td>
  45.  
  46. </tr>
  47.  
  48. }
  49. </table>
  50. }
  51. }
  52. <div>
  53. <p>
  54. <input type="submit" value=@ViewBag.ButtonText />
  55. </p>
  56. </div>
  57.  
  58. public ActionResult SendReminder(int id)
  59. {
  60. using (DatabaseEntities dbc = new DatabaseEntities())
  61. {
  62. DbSet<user> dbs = dbc.users;
  63. IQueryable<user> q = from p in dbs
  64. where p.Booking.event_id == id
  65. select p;
  66. List<user> model = q.ToList<user>();
  67. ViewBag.ButtonText = "Send Reminder Email";
  68.  
  69. return View("ViewDetails", model);
  70.  
  71. }
  72.  
  73. }
  74.  
  75. [HttpPost]
  76. public ActionResult SendReminder(string[] userId)
  77. {
  78. using (SmtpClient objSmtpClient = new SmtpClient())
  79. {
  80. for (int emailCount = 0; emailCount < userId.Length; emailCount++)
  81. {
  82. if (!string.IsNullOrEmpty(userId[emailCount]))
  83. {
  84. using (MailMessage mail = new MailMessage("sender@gmail.com", userId[emailCount].Trim()))
  85. {
  86. mail.Subject = "Test Email";
  87. mail.Body = "Test Body";
  88. mail.IsBodyHtml = true;
  89. using (SmtpClient smtp = new SmtpClient())
  90. {
  91. smtp.Host = "smtp.gmail.com";
  92. smtp.Port = 587;
  93. smtp.Credentials = new System.Net.NetworkCredential("sender@gmail.com", "password");
  94. smtp.EnableSsl = true;
  95. mail.IsBodyHtml = true;
  96. smtp.Send(mail);
  97. }
  98. }
  99. }
  100. }
  101. }
  102. return View();
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement