Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access email resource path in Keycloak?

I am customizing the email template for password-reset. I wish to access the logo from email resources directory (i.e) \themes\\email\resources\img\marketing.jpg

This can be possible for login module via ${url.resourcesPath}

Some one please point out me how to access the email resource path in password-reset.ftl

version keycloak-4.0.0.Final

like image 356
Vidhya - Vidhyadharan Avatar asked Jan 24 '26 20:01

Vidhya - Vidhyadharan


1 Answers

I ran into this problem myself, and after some searching I found this email thread:

Hi community,

I am looking for a way to add images to custom keycloak email themes. Our company template HTML uses the images sent as attachment. I would therefore like to attach the required images to the email. If this is not possible, what would be the correct way to add images to the HTML template?

Unfortunately the current documentation does not state anything of it: http://www.keycloak.org/docs/3.3/server_development/topics/themes.html

Regards Jonathan

 

I don't think you can do this out of the box today, but you should be able to create a custom email sender provider that does it. Look at docs for details on creating custom providers (as well as quickstarts on examples). Then look at EmailSenderProvider and the implementations in our repo.

 

Hi, If your goal is to display a kind of logo or some image in the mail, you can include it as an embedded image using <img src="data:image/png;base64,.... "/> It's not perfect as some email clients (like gmail) don't display this kind of image but it can do the trick before finding a better solution. BR, Jérôme.

 

Hi,

Thanks for your suggestions. After reading a lot about email client support for image embedding in emails (e.g. the solution from Jérôme is blocked by Outlook), I think the best solution is to implement my own email sender provider and link the images to the attachments (using CID) .

@Stian Thorgersen: My understanding is that I will have to override the EmailTemplateProvider based on the FreemarkerEmailTemplateProvider (or can I just extend from this one?) to fetch attachments from a path e.g. /attachments/ and pass them to the EmailSenderProvider, am I correct?

Regards Jonathan

So, whilst the documentation says you can use <img src="${url.resourcesPath}/img/image.jpg"> in your custom themes, this doesn't actually work for email templates.

UPDATE (2022): The documentation has changed over time, so this might be possible now, though I haven't verified that: https://www.keycloak.org/docs/latest/server_development/#adding-an-image-to-a-theme


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!