Search code examples
asp.net-coreasp.net-identityidentityserver4asp.net-core-identity

Confirmation email is sent even when RequireConfirmedEmail is set to false in .Net Core Identiy


I am implementing .Net Core Identity in my .net core 5.0 razor page application.

I have setup the identity to disable the email confirmation.

services.AddDefaultIdentity<ApplicationUser>(options =>
            {
                //Disable account confirmation.
                options.SignIn.RequireConfirmedAccount = false;
                options.SignIn.RequireConfirmedEmail = false;
                options.SignIn.RequireConfirmedPhoneNumber = false;
            })
            .AddEntityFrameworkStores<ApplicationDbContext>();

From the UI perspective the user is logged in without email confirmation. So, the UI is working just fine.

But the confirmation email is sent to the user anyway.

Here's how I have registered the Email Service:

services.AddTransient<IEmailSender, EmailSender>();

The reason for registering the email service is that I want to send the Reset Password email to the user.

I understand that the configuration says that the user does not have to be a confirmed user to login and do other activities.

How do I configure email service in a way that it does not send the confirmation email but allow other emails to be sent?


Solution

  • You can try to apply the scaffolder to add/generate the source code of registration, like below.

    enter image description here

    Check the OnPostAsync handler method defined in RegisterModel class, you can find the relevant code used to send email, then you can modify or comment out these block of code to achieve your requirement.

     await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                            $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");