Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @using SendEmail.Models @model List
- <user>
- @{ Layout = "~/Views/Shared/_Layout.cshtml"; }
- <h2>@ViewBag.ButtonText</h2>
- <script type="text/javascript" src="@Url.Content(" ~/Scripts/ ")jquery-1.10.2.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- $('#checkBoxAll').click(function() {
- if ($(this).is(":checked"))
- $('.chkCheckBoxId').prop('checked', true);
- else
- $('.chkCheckBoxId').prop('checked', false);
- });
- });
- </script>
- @if (ViewBag.ButtonText == "Send Reminder Email") {
- @using (Html.BeginForm("SendReminder", "ControllerName", FormMethod.Post))
- {
- <table>
- <tr>
- <th>First Name</th>
- <th>Last Name</th>
- <th>Email</th>
- <th>
- <input type="checkbox" id="checkBoxAll" />Select All</th>
- </tr>
- @foreach (user u in Model) {
- <tr>
- <td>@u.first_name</td>
- <td>@u.last_name</td>
- <td>@u.email</td>
- <td>
- <input type="checkbox" class="chkCheckBoxId" value="@u.email" name="userId" />
- </td>
- </tr>
- }
- </table>
- }
- }
- <div>
- <p>
- <input type="submit" value=@ViewBag.ButtonText />
- </p>
- </div>
- public ActionResult SendReminder(int id)
- {
- using (DatabaseEntities dbc = new DatabaseEntities())
- {
- DbSet<user> dbs = dbc.users;
- IQueryable<user> q = from p in dbs
- where p.Booking.event_id == id
- select p;
- List<user> model = q.ToList<user>();
- ViewBag.ButtonText = "Send Reminder Email";
- return View("ViewDetails", model);
- }
- }
- [HttpPost]
- public ActionResult SendReminder(string[] userId)
- {
- using (SmtpClient objSmtpClient = new SmtpClient())
- {
- for (int emailCount = 0; emailCount < userId.Length; emailCount++)
- {
- if (!string.IsNullOrEmpty(userId[emailCount]))
- {
- using (MailMessage mail = new MailMessage("sender@gmail.com", userId[emailCount].Trim()))
- {
- mail.Subject = "Test Email";
- mail.Body = "Test Body";
- mail.IsBodyHtml = true;
- using (SmtpClient smtp = new SmtpClient())
- {
- smtp.Host = "smtp.gmail.com";
- smtp.Port = 587;
- smtp.Credentials = new System.Net.NetworkCredential("sender@gmail.com", "password");
- smtp.EnableSsl = true;
- mail.IsBodyHtml = true;
- smtp.Send(mail);
- }
- }
- }
- }
- }
- return View();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement