Search code examples
emailthemeskeycloak

Keycloak Add user's name in email theme template


I am creating an email theme for keycloak. So, when a user forgets their password and requests for a link to reset it; an email is sent to the user.

Now, I am cutomizing the email that he/she gets. I want to add the user's name. Can I do that?

I do have access to variables including: link to reset password link expiration time realm name

How do I get the user's name so that the email template says

Hello John,

blah blah blah


Solution

  • You can add user.getUsername() in your .ftl file

    open (email/text) *.ftl file and add user.getUsername() as one of the parameters like

    ${msg("passwordResetBody", link, linkExpiration, realmName, user.getUsername())}
    

    and then update actual message body at (email/messages/messages_en.properties) with zero-indexed parameter number like {2} or {3} (in this case it is {3})