Ashima
Ashima

Reputation: 4834

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

Upvotes: 13

Views: 10134

Answers (2)

meetarun
meetarun

Reputation: 569

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})

Upvotes: 23

Cornelius Roemer
Cornelius Roemer

Reputation: 8346

To complement the accepted answer: Per codehumsafar, back in 2018, the following parameters could be accessed via respective methods:

User name:        user.getUsername() 
Email:            user.getEmail() 
First name:       user.getFirstName() 
Last name:        user.getLastName()

Possibly custom fields added to user might be accessible as well, if you know how, please comment!

Upvotes: 0

Related Questions