Open Closed

how to avoid sending the email confirmation email twice #8676


User avatar
0
LiSong created
  • ABP Framework version: v9.X.X
  • UI Type: Angular / MVC / Blazor WASM / Blazor Server
  • Database System: SQL Server
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes/no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

When an user created a new account, the confirm your email page shows, and there is a Verify button, before they click the button, a confirmation email was sent to their inbox, and if the users click the Verifiy button again, they receive another same email again. is there a way to avoid this? for instance, wait they click the Verify button before sending the first email; or check the email sent log(is there logs for this), if the same email has been sent, prevent the system to send it twice. any suggestions?


4 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    In the latest version, the button will be hidden to prevent multiple send email.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    If you want to check on the server side, you can try to override the SendEmailConfirmationTokenAsync method.

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(AccountAppService))]
    public class MyAccountAppService : AccountAppService
    {
        protected override async Task SendEmailConfirmationTokenAsync(IdentityUser user,
            string applicationName,
            string returnUrl,
            string returnUrlHash)
        {
            var isEmailSent = // get from cache or db.
            if(isEmailSent){
                throw new UserfriendlyException("...")
            }else{
                var confirmationToken = await UserManager.GenerateEmailConfirmationTokenAsync(user);
                await AccountEmailer.SendEmailConfirmationLinkAsync(user, confirmationToken, applicationName, returnUrl, returnUrlHash);
                // add confirmationToken to cache or db
            }
            
        }
    }
    
  • User Avatar
    0
    LiSong created

    In the latest version, the button will be hidden to prevent multiple send email.

    Which version?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi, 9.0.3

Made with ❤️ on ABP v9.2.0-preview. Updated on January 20, 2025, 07:44