public ActionResult RegForm(RegResponse rr, string id) { try { if (ModelState.IsValid) { AReg reg = new AReg(); reg.TourID = id; reg.TourDate = rr.EventInfo.TourDate; reg.RegFirstName = rr.FirstName; reg.RegLastName = rr.LastName; reg.RegBirthday = rr.Birthday; reg.UserID = rr.UserInfo.UserID; reg.RegTime = DateTime.Now; reg.WillAttend = rr.WillAttend; BTourGuideOp tourOp = new BTourGuideOp(); tourOp.AddReg(reg); // Send email to user: // Email stuff string subject = "Your registartion to the tour " + rr.EventInfo.TourName + " on " + rr.EventInfo.TourDate.ToString("dd-MM-yyyy"); string body = "Thank you for your registartion to the tour " + rr.EventInfo.TourName + " on " + rr.EventInfo.TourDate.ToString("dd-MM-yyyy") + "<br />" + "Registration name: " + rr.FirstName + " " + rr.LastName + "<br />" + "<a href='" + Url.Action("EventDetails", "Home", new { id = rr.EventInfo.TourID, date = rr.EventInfo.TourDate }, "http") + "'>Click here</a> to see the tour details." + "<br />" + "To see your user profile <a href='" + Url.Action("UserProfile", "Account", new { username = rr.UserInfo.Username }, "http") + "'>Click here</a>"; string from = "*****@*****.**"; MailMessage message = new MailMessage(from, rr.UserInfo.UserEmail); message.Subject = subject; message.Body = body; message.IsBodyHtml = true; SmtpClient client = new SmtpClient("smtp.gmail.com", 587) { UseDefaultCredentials = false, EnableSsl = true, Timeout = 20000, Credentials = new NetworkCredential("*****@*****.**", "henhqwcfvmtzplgb") }; // Attempt to send the email try { client.Send(message); // Updating the IsSentEmail in the DB tourOp.UpdateEmailSent(rr.UserInfo.UserID, rr.FirstName, rr.LastName, rr.EventInfo.TourID, rr.EventInfo.TourDate, true); return View("ThankYou", rr); } catch (Exception e) { TempData["EmailException"] = "Issue sending email: " + e.Message; return View(rr); } } else return View(rr); } catch(Exception e) { TempData["Exception"] = "" + e.Message; return View(rr); } }