public async Task<ActionResult> AddClient(RegisterViewModel model) { if (ModelState.IsValid) { _clientBl.AddClient(model); string code = await UserManager.GenerateEmailConfirmationTokenAsync(_clientBl.UserId); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = _clientBl.UserId, code }, Request.Url.Scheme); _email.SendEmail(_clientBl.SendEmail(model),model,callbackUrl); return RedirectToAction("GetAllClients"); } return View(model); }
public void SendEmail(string message, RegisterViewModel model, string callbackUrl) { var boddy = new StringBuilder(); var boddyConf = new StringBuilder(); boddy.Append(message); string confirmMessage = "Hi! " + model.Email + "<br/>" + "Click the link to confirm your account " + callbackUrl; boddyConf.Append(confirmMessage); string bodyForConf = boddyConf.ToString(); string bodyFor = boddy.ToString(); string subjectFor = "Registration"; string subjectForConf = "Confirm Email"; string toFor = model.Email; var mail = new MailAddress("*****@*****.**", "EGO-Administrators"); WebMail.SmtpServer = "pod51014.outlook.com"; WebMail.SmtpPort = 587; WebMail.UserName = "******"; WebMail.Password = "******"; WebMail.From = mail.ToString(); WebMail.EnableSsl = true; try { WebMail.Send(toFor, subjectFor, bodyFor); } catch { // ignored } try { WebMail.Send(toFor, subjectForConf, bodyForConf); } catch { //null } }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, false, false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }