Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Authorize]
- [Route("confirm", Name = "ConfirmEmail")]
- public async Task<ActionResult> ConfirmEmail()
- {
- var user = await UserManager.FindByNameAsync(User.Identity.Name);
- if (user != null)
- {
- var provider = new DpapiDataProtectionProvider("InternetShop");
- UserManager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(provider.Create("EmailConfirmation"));
- string token = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
- string callBack = Url.RouteUrl("ConfirmEmail", new { userId = user.Id, token },
- protocol: Request.Url.Scheme);
- await UserManager.SendEmailAsync(user.Id, "Confirm email", $"For a registration competion" +
- $"please folow the link: {callBack}");
- ViewBag.email = user.Email;
- return View("SendConfirmationCode");
- }
- else return View("Error");
- }
- public class EmailService : IIdentityMessageService
- {
- public Task SendAsync(IdentityMessage message)
- {
- var from = ConfigurationManager.AppSettings["Email"];
- var pass = ConfigurationManager.AppSettings["Password"];
- SmtpClient client = new SmtpClient("smtp.yandex.ru", 25);
- client.DeliveryMethod = SmtpDeliveryMethod.Network;
- client.UseDefaultCredentials = false;
- client.Credentials = new System.Net.NetworkCredential(from, pass);
- client.EnableSsl = true;
- var mail = new MailMessage(from, message.Destination);
- mail.Subject = message.Subject;
- mail.Body = message.Body;
- mail.IsBodyHtml = true;
- return client.SendMailAsync(mail);
- }
- }
Add Comment
Please, Sign In to add comment