Keycloak Add user's name in email theme template
Asked Answered
T

2

13

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

Tremblay answered 12/5, 2016 at 23:48 Comment(0)
S
23

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

Sainfoin answered 13/5, 2016 at 10:55 Comment(4)
user.username did not work but user.getUsername() did.Tremblay
@Ishita How much it is safe to send username and password reset details in the same email,what if email sent to wrong emailid?Denude
would first name be user.firstName?Sean
@Sean for firstname you can use user.getFirstName() check more here codehumsafar.wordpress.com/2018/09/24/…Acyclic
C
0

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!

Calvados answered 24/7, 2024 at 13:12 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.