keycloakmailhog

Keycloak not sending email on new User Registration


I'm on a Mac, and I'm trying to get Keycloak 24.0.2 (running as a Docker container) to send emails as part of User Registration. I have Mailhog running locally and I have configured Keycloak to send emails to it, and have successfully tested that connection:

enter image description here

So I know Keycloak can send email to Mailhog.

In the Keycloak Realm Settings >> Login tab, I enable User Registration:

enter image description here

When I open my app and go to an authenticated page, it correctly redirects me to the Keycloak Login screen, and I can now see a Register link at the bottom:

enter image description here

So far, so good. I click "Register" and proceed to fill out the Registration form:

enter image description here

I click "Register" and I am correctly redirected back into my app.

In Keycloak, I see the new user registration event:

enter image description here

When I click into the REGISTER event, I see the new user that was created:

enter image description here

However, when I refresh my screen in Mailhog, I see no emails were sent. Furthermore, if I look at the Keycloak logs (vid docker logs) I see no log output, errors, etc.

Is there anything I need to do to configure Keycloak to send emails when a new user registers? Did I forget any steps at all? If not, can anyone spot where I'm going awry, or lend ideas for troubleshooting?


Solution

  • I got this working, after reaching out to the Keycloak team on Slack, who provided excellent support!

    I had forgotten to enable Verify email under Realm Settings >> Email Settings.

    So that takes care of sending emails when the user self-registers.

    To get email sending working when an Admin creates a new user in the Keycloak admin console/UI, it was a bit trickier, but I got it working as well:

    1. Create a new user and make sure to select Verify email from the Required user actions dropdown
    2. Immediately add a password (temporary or permanent, makes no difference) under the users Credentials tab
    3. In your client app, go to sign in as that user (with the new password you just created for them)
    4. The system will now send an email to that user, requiring them to verify their email before allowing them access into the app

    I'm not in love with that work flow, because it requries the admin to send the user their temp/permanent password somehow prior to them logging in for the first time. But with Keycloak's REST API I believe I will find a way to use the same endpoints under the hood but to create a more UX-focused, homegrown "invite new user" feature.