diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/html/email-verification.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/html/email-verification.ftl new file mode 100644 index 0000000000..eb7682a272 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/keycloak/email/html/email-verification.ftl @@ -0,0 +1,5 @@ + +
+${msg("emailVerificationBodyHtml",link, linkExpiration, realmName)} + + diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-login_error.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-login_error.ftl new file mode 100644 index 0000000000..d31410307c --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-login_error.ftl @@ -0,0 +1,5 @@ + + +${msg("eventLoginErrorBodyHtml",event.date,event.ipAddress)} + + diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-remove_totp.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-remove_totp.ftl new file mode 100644 index 0000000000..91699ea349 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-remove_totp.ftl @@ -0,0 +1,5 @@ + + +${msg("eventRemoveTotpBodyHtml",event.date, event.ipAddress)} + + diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-update_password.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-update_password.ftl new file mode 100644 index 0000000000..8a6da60a50 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-update_password.ftl @@ -0,0 +1,5 @@ + + +${msg("eventUpdatePasswordBodyHtml",event.date, event.ipAddress)} + + diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-update_totp.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-update_totp.ftl new file mode 100644 index 0000000000..c0190c7278 --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/keycloak/email/html/event-update_totp.ftl @@ -0,0 +1,5 @@ + + +${msg("eventUpdateTotpBodyHtml",event.date, event.ipAddress)} + + diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/html/password-reset.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/html/password-reset.ftl new file mode 100644 index 0000000000..846b45dafd --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/keycloak/email/html/password-reset.ftl @@ -0,0 +1,5 @@ + + +${msg("passwordResetBodyHtml",link, linkExpiration, realmName)} + + \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_de.properties b/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_de.properties index 0256640286..91337c4ee8 100644 --- a/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_de.properties +++ b/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_de.properties @@ -1,12 +1,18 @@ emailVerificationSubject=E-Mail verifizieren passwordResetSubject=Passwort zur\u00FCckzusetzen passwordResetBody=Jemand hat angefordert Ihr {2} Passwort zur\u00FCckzusetzen. Falls das Sie waren, dann klicken Sie auf den folgenden Link um das Passwort zur\u00FCckzusetzen.\n\n{0}\n\nDieser Link wird in {1} Minuten ablaufen.\n\nFalls Sie das Passwort nicht zur\u00FCcksetzen m\u00F6chten, dann k\u00F6nnen Sie diese E-Mail ignorieren. +passwordResetBodyHtml=Jemand hat angefordert Ihr {2} Passwort zur\u00FCckzusetzen. Falls das Sie waren, dann klicken Sie auf den folgenden Link um das Passwort zur\u00FCckzusetzen.
Dieser Link wird in {1} Minuten ablaufen.
Falls Sie das Passwort nicht zur\u00FCcksetzen m\u00F6chten, dann k\u00F6nnen Sie diese E-Mail ignorieren.
emailVerificationBody=Jemand hat ein {2} Konto mit dieser E-Mail Adresse erstellt. Fall das Sie waren, dann klicken Sie auf den Link um die E-Mail Adresse zu verifizieren.\n\n{0}\n\nDieser Link wird in {1} Minuten ablaufen.\n\nFalls Sie dieses Konto nicht erstellt haben, dann k\u00F6nnen sie diese Nachricht ignorieren. +emailVerificationBodyHtml=Jemand hat ein {2} Konto mit dieser E-Mail Adresse erstellt. Fall das Sie waren, dann klicken Sie auf den Link um die E-Mail Adresse zu verifizieren.
Dieser Link wird in {1} Minuten ablaufen.
Falls Sie dieses Konto nicht erstellt haben, dann k\u00F6nnen sie diese Nachricht ignorieren.
eventLoginErrorSubject=Fehlgeschlagene Anmeldung eventLoginErrorBody=Jemand hat um {0} von {1} versucht sich mit ihrem Konto anzumelden. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin. +eventLoginErrorBodyHtml=Jemand hat um {0} von {1} versucht sich mit ihrem Konto anzumelden. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin.
eventRemoveTotpSubject=TOTP Entfernt eventRemoveTotpBody=TOTP wurde von ihrem Konto am {0} von {1} entfernt. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin. +eventRemoveTotpBodyHtml=TOTP wurde von ihrem Konto am {0} von {1} entfernt. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin.
eventUpdatePasswordSubject=Passwort Aktualisiert eventUpdatePasswordBody=Ihr Passwort wurde am {0} von {1} ge\u00E4ndert. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin. +eventUpdatePasswordBodyHtml=Ihr Passwort wurde am {0} von {1} ge\u00E4ndert. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin.
eventUpdateTotpSubject=TOTP Aktualisiert eventUpdateTotpBody=TOTP wurde am {0} von {1} ge\u00E4ndert. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin. +eventUpdateTotpBodyHtml=TOTP wurde am {0} von {1} ge\u00E4ndert. Falls das nicht Sie waren, dann kontaktieren Sie bitte Ihren Admin.
diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_en.properties b/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_en.properties index c0afc9ca91..7a3ac65499 100755 --- a/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_en.properties +++ b/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_en.properties @@ -1,12 +1,18 @@ emailVerificationSubject=Verify email emailVerificationBody=Someone has created a {2} account with this email address. If this was you, click the link below to verify your email address\n\n{0}\n\nThis link will expire within {1} minutes.\n\nIf you didn''t create this account, just ignore this message. +emailVerificationBodyHtml=Someone has created a {2} account with this email address. If this was you, click the link below to verify your email address
This link will expire within {1} minutes.
If you didn''t create this account, just ignore this message.
passwordResetSubject=Reset password passwordResetBody=Someone just requested to change your {2} account''s password. If this was you, click on the link below to set a new password\n\n{0}\n\nThis link will expire within {1} minutes.\n\nIf you don''t want to reset your password, just ignore this message and nothing will be changed. +passwordResetBodyHtml=Someone just requested to change your {2} account''s password. If this was you, click on the link below to set a new password
This link will expire within {1} minutes.
If you don''t want to reset your password, just ignore this message and nothing will be changed.
eventLoginErrorSubject=Login error -eventLoginErrorBody=A failed login attempt was dettected to your account on {0} from {1}. If this was not you, please contact an admin. +eventLoginErrorBody=A failed login attempt was detected to your account on {0} from {1}. If this was not you, please contact an admin. +eventLoginErrorBodyHtml=A failed login attempt was detected to your account on {0} from {1}. If this was not you, please contact an admin.
eventRemoveTotpSubject=Remove TOTP eventRemoveTotpBody=TOTP was removed from your account on {0} from {1}. If this was not you, please contact an admin. +eventRemoveTotpBodyHtml=TOTP was removed from your account on {0} from {1}. If this was not you, please contact an admin.
eventUpdatePasswordSubject=Update password eventUpdatePasswordBody=Your password was changed on {0} from {1}. If this was not you, please contact an admin. +eventUpdatePasswordBodyHtml=Your password was changed on {0} from {1}. If this was not you, please contact an admin.
eventUpdateTotpSubject=Update TOTP -eventUpdateTotpBody=TOTP was updated for your account on {0} from {1}. If this was not you, please contact an admin. \ No newline at end of file +eventUpdateTotpBody=TOTP was updated for your account on {0} from {1}. If this was not you, please contact an admin. +eventUpdateTotpBodyHtml=TOTP was updated for your account on {0} from {1}. If this was not you, please contact an admin.
diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_pt_BR.properties b/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_pt_BR.properties index 0316e19009..fff7e10475 100644 --- a/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_pt_BR.properties +++ b/forms/common-themes/src/main/resources/theme/keycloak/email/messages/messages_pt_BR.properties @@ -1,12 +1,18 @@ emailVerificationSubject=Verifica\u00E7\u00E3o de e-mail emailVerificationBody=Algu\u00E9m criou uma conta {2} com este endere\u00E7o de e-mail. Se foi voc\u00EA, clique no link abaixo para verificar o seu endere\u00E7o de email\n\n{0}\n\nEste link ir\u00E1 expirar dentro de {1} minutos.\n\nSe n\u00E3o foi voc\u00EA que criou esta conta, basta ignorar esta mensagem. +emailVerificationBodyHtml=Algu\u00E9m criou uma conta {2} com este endere\u00E7o de e-mail. Se foi voc\u00EA, clique no link abaixo para verificar o seu endere\u00E7o de email
Este link ir\u00E1 expirar dentro de {1} minutos.
Se n\u00E3o foi voc\u00EA que criou esta conta, basta ignorar esta mensagem.
passwordResetSubject=Redefini\u00E7\u00E3o de senha passwordResetBody=Algu\u00E9m pediu para mudar a senha de sua conta {2}. Se foi voc\u00EA, clique no link abaixo para definir uma nova senha\n\n{0}\n\nEste link ir\u00E1 expirar dentro de {1} minutos.\n\nSe voc\u00EA n\u00E3o deseja redefinir sua senha, basta ignorar esta mensagem e nada ser\u00E1 mudado. +passwordResetBodyHtml=Algu\u00E9m pediu para mudar a senha de sua conta {2}. Se foi voc\u00EA, clique no link abaixo para definir uma nova senha
Este link ir\u00E1 expirar dentro de {1} minutos.
Se voc\u00EA n\u00E3o deseja redefinir sua senha, basta ignorar esta mensagem e nada ser\u00E1 mudado.
eventLoginErrorSubject=Erro de login eventLoginErrorBody=Uma tentativa de login mal sucedida para a sua conta foi detectada em {0} de {1}. Se n\u00E3o foi voc\u00EA, por favor, entre em contato com um administrador. +eventLoginErrorBodyHtml=Uma tentativa de login mal sucedida para a sua conta foi detectada em {0} de {1}. Se n\u00E3o foi voc\u00EA, por favor, entre em contato com um administrador.
eventRemoveTotpSubject=Remover TOTP eventRemoveTotpBody=TOTP foi removido da sua conta em {0} de {1}. Se n\u00E3o foi voc\u00EA, por favor, entre em contato com um administrador. +eventRemoveTotpBodyHtml=TOTP foi removido da sua conta em {0} de {1}. Se n\u00E3o foi voc\u00EA, por favor, entre em contato com um administrador.
eventUpdatePasswordSubject=Atualiza\u00E7\u00E3o de senha eventUpdatePasswordBody=Sua senha foi alterada em {0} de {1}. Se n\u00E3o foi voc\u00EA, por favor, entre em contato com um administrador. +eventUpdatePasswordBodyHtml=Sua senha foi alterada em {0} de {1}. Se n\u00E3o foi voc\u00EA, por favor, entre em contato com um administrador.
eventUpdateTotpSubject=Atualiza\u00E7\u00E3o TOTP eventUpdateTotpBody=TOTP foi atualizado para a sua conta em {0} de {1}. Se n\u00E3o foi voc\u00EA, por favor, entre em contato com um administrador. +eventUpdateTotpBodyHtml=TOTP foi atualizado para a sua conta em {0} de {1}. Se n\u00E3o foi voc\u00EA, por favor, entre em contato com um administrador.
diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/email-verification.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/text/email-verification.ftl similarity index 100% rename from forms/common-themes/src/main/resources/theme/keycloak/email/email-verification.ftl rename to forms/common-themes/src/main/resources/theme/keycloak/email/text/email-verification.ftl diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/event-login_error.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/text/event-login_error.ftl similarity index 100% rename from forms/common-themes/src/main/resources/theme/keycloak/email/event-login_error.ftl rename to forms/common-themes/src/main/resources/theme/keycloak/email/text/event-login_error.ftl diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/event-remove_totp.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/text/event-remove_totp.ftl similarity index 100% rename from forms/common-themes/src/main/resources/theme/keycloak/email/event-remove_totp.ftl rename to forms/common-themes/src/main/resources/theme/keycloak/email/text/event-remove_totp.ftl diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/event-update_password.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/text/event-update_password.ftl similarity index 100% rename from forms/common-themes/src/main/resources/theme/keycloak/email/event-update_password.ftl rename to forms/common-themes/src/main/resources/theme/keycloak/email/text/event-update_password.ftl diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/event-update_totp.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/text/event-update_totp.ftl similarity index 100% rename from forms/common-themes/src/main/resources/theme/keycloak/email/event-update_totp.ftl rename to forms/common-themes/src/main/resources/theme/keycloak/email/text/event-update_totp.ftl diff --git a/forms/common-themes/src/main/resources/theme/keycloak/email/password-reset.ftl b/forms/common-themes/src/main/resources/theme/keycloak/email/text/password-reset.ftl similarity index 100% rename from forms/common-themes/src/main/resources/theme/keycloak/email/password-reset.ftl rename to forms/common-themes/src/main/resources/theme/keycloak/email/text/password-reset.ftl diff --git a/forms/email-freemarker/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailProvider.java b/forms/email-freemarker/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailProvider.java index 95f55f3674..79080de2c2 100755 --- a/forms/email-freemarker/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailProvider.java +++ b/forms/email-freemarker/src/main/java/org/keycloak/email/freemarker/FreeMarkerEmailProvider.java @@ -1,11 +1,28 @@ package org.keycloak.email.freemarker; +import java.text.MessageFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Properties; + +import javax.mail.Message; +import javax.mail.Multipart; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; + import org.jboss.logging.Logger; import org.keycloak.email.EmailException; import org.keycloak.email.EmailProvider; import org.keycloak.email.freemarker.beans.EventBean; import org.keycloak.events.Event; import org.keycloak.events.EventType; +import org.keycloak.freemarker.FreeMarkerException; import org.keycloak.freemarker.FreeMarkerUtil; import org.keycloak.freemarker.LocaleHelper; import org.keycloak.freemarker.Theme; @@ -15,14 +32,6 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; import org.keycloak.models.UserModel; -import javax.mail.Message; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import java.text.MessageFormat; -import java.util.*; - /** * @author Stian Thorgersen */ @@ -93,16 +102,29 @@ public class FreeMarkerEmailProvider implements EmailProvider { Properties rb = theme.getMessages(locale); attributes.put("msg", new MessageFormatterMethod(locale, rb)); String subject = new MessageFormat(rb.getProperty(subjectKey,subjectKey),locale).format(new Object[0]); - String body = freeMarker.processTemplate(attributes, template, theme); + String textTemplate = String.format("text/%s", template); + String textBody; + try { + textBody = freeMarker.processTemplate(attributes, textTemplate, theme); + } catch (final FreeMarkerException e ) { + textBody = null; + } + String htmlTemplate = String.format("html/%s", template); + String htmlBody; + try { + htmlBody = freeMarker.processTemplate(attributes, htmlTemplate, theme); + } catch (final FreeMarkerException e ) { + htmlBody = null; + } - send(subject, body); + send(subject, textBody, htmlBody); } catch (Exception e) { throw new EmailException("Failed to template email", e); } } - private void send(String subject, String body) throws EmailException { + private void send(String subject, String textBody, String htmlBody) throws EmailException { try { String address = user.getEmail(); Map