private void SendVerificationMail(RegisterModel user, string token) { string confirmUrl = Url.Action("Confirm", "Account", new { id = token }, Request.Url.Scheme); MailMessage email = new MailMessage("*****@*****.**", user.Email); email.Subject = "Welcome!"; email.Body = "Activation link: " + confirmUrl; SmtpClient smtp = new SmtpClient(); try { smtp.Send(email); } catch (Exception){ throw; } }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { string token = WebSecurity.CreateUserAndAccount(model.Email, model.Password, new { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email }, true); SendVerificationMail(model, token); //WebSecurity.Login(model.Email, model.Password); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }