简体   繁体   English

如何访问Keycloak中的电子邮件资源路径?

[英]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 (ie) \\themes\\\\email\\resources\\img\\marketing.jpg 我希望从电子邮件资源目录(即\\ themes \\\\ email \\ resources \\ img \\ marketing.jpg )访问徽标

This can be possible for login module via ${url.resourcesPath} 对于登录模块,可以通过$ {url.resourcesPath}实现

Some one please point out me how to access the email resource path in password-reset.ftl 请有人指出我如何访问password-reset.ftl中的电子邮件资源路径

version keycloak-4.0.0.Final 版本keycloak-4.0.0.Final

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. 我正在寻找一种将图像添加到自定义keycloak电子邮件主题的方法。 Our company template HTML uses the images sent as attachment. 我们公司的模板HTML使用作为附件发送的图像。 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? 如果这不可能,将图像添加到HTML模板的正确方法是什么?

Unfortunately the current documentation does not state anything of it: http://www.keycloak.org/docs/3.3/server_development/topics/themes.html 不幸的是,当前文档没有说明任何内容: 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. 然后在我们的仓库中查看EmailSenderProvider和实现。

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. 嗨,如果您的目标是在邮件中显示某种徽标或某些图像,则可以使用<img src="data:image/png;base64,.... "/>将其作为嵌入式图像包含在内<img src="data:image/png;base64,.... "/>完美,因为某些电子邮件客户端(例如gmail)不会显示此类图像,但是在找到更好的解决方案之前它可以解决问题。 BR, Jérôme. BR,杰​​罗姆。

Hi, 你好

Thanks for your suggestions. 感谢您的建议。 After reading a lot about email client support for image embedding in emails (eg 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) . 在阅读了很多有关电子邮件客户端对图像嵌入电子邮件的支持之后(例如,Jérôme的解决方案被Outlook阻止),我认为最好的解决方案是实现自己的电子邮件发件人提供程序并将图像链接到附件(使用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 eg /attachments/ and pass them to the EmailSenderProvider, am I correct? @Stian Thorgersen:我的理解是,我将不得不基于FreemarkerEmailTemplateProvider重写EmailTemplateProvider(或者我可以从这个扩展吗?)以从/ attachments /路径中获取附件,并将其传递给EmailSenderProvider,对吗? ?

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. 因此,尽管文档说您可以在自定义主题中使用<img src="${url.resourcesPath}/img/image.jpg"> ,但这实际上不适用于电子邮件模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM