How to include username in reset password email

Hi everyone,

I have successfully altered the reset password body for my custom theme by adding a /email/messages/messages_en.properties file inside my theme with a passwordResetBody property in it.

I’m wondering if there is a way to include the user’s username in the reset password email they receive.

I know that the password-reset.ftl file is what generates the contents of the email.

And I know that the parameters passed in to msg() are used as positional parameters in the internationalization message passwordResetBody i.e. {0} is replaced with the value of link.

Is there a variable I could use such as username so that I could have a password-reset.ftl file in my theme that passes in an extra parameter like so?

<#ftl output_format="plainText">
${msg("passwordResetBody",link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration), username)}
1 Like

Hello tylervz, you can do

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

and add {4} in your message_en.properties.

You can also get username info or email by doing this :

Email: ${user.email}
Username: ${user.username}
1 Like

Hi @AhmedBouk thank you for the response! The {4} placeholder in my message is not getting replaced, so it looks like my custom password-reset.ftl file is not being used. For my theme that is named mytheme, I have it placed in /themes/mytheme/email/text/password-reset.ftl . Is there something that I am missing?

1 Like

Same issue I’m facing. Searched so far but didn’t find any solution. Do you get the solution for this?

Are you sure that is not html/password-reset.ftl that is missing ?
You should have both html/password-reset.ftl and text/password-reset.ftl

Hi @pjmalandrino that ended up being the issue.

I needed to have the file /themes/mytheme/email/html/password-reset.ftl in my theme as well. It has the contents:

<html>
<body>
${kcSanitize(msg("passwordResetBodyHtml",link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration), user.username))?no_esc}
</body>
</html>

For any other readers who come across this thread, I got it working using Keycloak 16.1.1 .

3 Likes