Asp.net Core 3.0 Identity confirmation using smtp account and password recovery

When a new core project, the use of identity-based frame, confirmation error has occurred, and is not working.

Establish documentation here

https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-3.1&tabs=visual-studio#scaffold-identity-into-an-empty-project

After the reference was found, did not implement this interface, so you need to complete, which is the official document, but a third-party key official

https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/accconfirm?view=aspnetcore-3.1&tabs=visual-studio#require-email-confirmation

Next, using its own habit of it, is to send content to users with their own mailbox.

And official documents, like the establishment of a EmailSender

Brothers access codes:

public class EmailSender : IEmailSender
    {

        public async Task SendEmailAsync(string email, string subject, string message)
        {

            // 设置邮件内容
            var mail = new MailMessage(
                new MailAddress("[email protected]", "王彬"),
                new MailAddress(email)
                );
            mail.Subject = subject;
            mail.Body =Message; 
            mail.IsBodyHtml = to true ; 
            mail.BodyEncoding = Encoding.UTF8; 
            mail.Priority = MailPriority.High; // message priority
                                               // SMTP server 
            var SMTP = new new the SmtpClient ( " smtp.163.com " , 25 ) ; 
            smtp.UseDefaultCredentials = to false ; 
            smtp.Credentials = new new System.Net.NetworkCredential ( " [email protected] " ,"*******“;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            await smtp.SendMailAsync(mail);

        }
    }

Then, we add the following code to Startup.cs file  ConfigureServices method:  

  • It will be  EmailSender added as a temporary service.
  • Sign up  AuthMessageSenderOptions configuration examples.
services.AddTransient<IEmailSender, EmailSender>();

  

Well, the rest is the official one to the content. identity is still very convenient.

Guess you like

Origin www.cnblogs.com/wangbin5542/p/12018921.html