我已经为 Keycloak 电子邮件创建了一个自定义主题。
我知道如何在电子邮件正文中添加领域名称,但我没有找到如何在主题中添加领域名称。
是否有可能在不需要自定义提供程序的情况下添加此内容?
谢谢!
最佳答案
有同样的问题。
因此进行了一些研究(通过代码),并发现在编写此答案时,默认的基于 Freemarker 的电子邮件实现甚至不提供主题属性(称为变量或参数)以及最终主题字符串格式化是基于空属性列表完成的。 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
的代码跟踪中,我找不到任何允许在主题行中添加动态值/变量的逻辑。
为了解决这个问题,我提出了一个问题。完成后我会链接它。
更新 1
问题已打开:https://github.com/keycloak/keycloak/issues/11883
更新2
关于keycloak - 如何在自定义电子邮件模板主题中添加领域名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72058054/