如何在自定义电子邮件模板Subject中添加Realm名称



我已经为Keycloak电子邮件创建了一个自定义主题。

我知道如何在邮件正文中添加域名,但我不知道如何在主题中添加域名。

有没有可能在不需要自定义提供商的情况下添加这个?

谢谢的!

我也有同样的问题。

所以我做了一些研究(通过代码),发现在写这个答案的时候,默认的基于freemarker的Email Implementation甚至没有提供主题属性(称它们为变量或参数),最终的主题字符串格式化是基于一个空的属性列表完成的。https://github.com/keycloak/keycloak/blob/bfce612641a70e106b20b136431f0e4046b5c37f/services/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailTemplateProvider.java L162
@Override
public void sendExecuteActions(String link, long expirationInMinutes) throws EmailException {
Map<String, Object> attributes = new HashMap<>(this.attributes);
attributes.put("user", new ProfileBean(user));
addLinkInfoIntoAttributes(link, expirationInMinutes, attributes);
attributes.put("realmName", getRealmName());
send("executeActionsSubject", "executeActions.ftl", attributes);
}

返回调用

@Override
public void send(String subjectFormatKey, String bodyTemplate, Map<String, Object> bodyAttributes) throws EmailException {
send(subjectFormatKey, Collections.emptyList(), bodyTemplate, bodyAttributes);
}

最后,这个函数被执行

protected EmailTemplate processTemplate(String subjectKey, List<Object> subjectAttributes, String template, Map<String, Object> attributes) throws EmailException {
try {
........
String subject = new MessageFormat(rb.getProperty(subjectKey, subjectKey), locale).format(subjectAttributes.toArray());
........

executeAction的整个代码跟踪中,我没有发现任何允许在主题行中添加动态值/变量的逻辑。

为了解决这个问题,我提出了一个问题。我将链接它一旦完成。 <标题>

更新1Issue打开:https://github.com/keycloak/keycloak/issues/11883

<标题>更新2 h1> R raise: https://github.com/keycloak/keycloak/pull/11885

最新更新