I can't send image in email

802 views
Skip to first unread message

Gustavo Farias Veloso Carvalho

unread,
Aug 12, 2021, 5:42:36 PM8/12/21
to Keycloak User

Hello, good night everyone, everything good?

I started using keycloak a little while ago and I'm modifying the email sending template for password recovery.

The email is successfully sent without an image!

But when I add the <img src="..." alt=""> tag it doesn't send and I get the following error: Failed to template email.

I've also tried creating a directory called resources/img/images.jpeg inside my customTemplate, and using the <img src="${resourcesPath}"> but it didn't work either.

By any chance, would you know how to give me a direction on how I might be solving this problem?

Thank you in advance, best regards.

Message has been deleted

Gustavo Farias Veloso Carvalho

unread,
Aug 12, 2021, 5:52:45 PM8/12/21
to Keycloak User
My code is this:

password-reset.ftl

<html>
<head>
</head>
<body>
    <table style="border-collapse:collapse" width="600" cellspacing="0" cellpadding="0" border="0" align="center">
        <tbody>
            <tr>
                <td style="padding:40px 0 30px 0" align="center">
                    <img src="${url.resourcesPath}/img/img3.png" alt="Logo" border="0">
                </td>
            </tr>
            <tr>
                <td>
                    <#ftl output_format="plainText">${msg("passwordResetBody",link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration))}
                </td>
            </tr>
            <tr>
                <td>
                    <img src="${url.resourcesPath}/img/img2.jog" alt="Espaçamento" border="0">
                </td>
            </tr>
        </tbody>
    </table>
    <div align="center">
        <img src="${url.resourcesPath}/img/img1.jpg" alt="Card" border="0" height="30">
    </div>
</body>

</html>


I've tried using:
        <img src="${url.resourcesPath}/img/img1.jpg" alt="Card" border="0" height="30">
        <img src="${resourcesPath}/img/img1.jpg" alt="Card" border="0" height="30">
        <img src="https://anysite.com/img1.jpg" alt="Card" border="0" height="30">

And when I remove the <img> tag the email is sent successfully!

Tobias Häfner

unread,
Aug 13, 2021, 2:31:02 AM8/13/21
to Keycloak User
<img src="${url.resourcesPath}/img/img2.jog

Maybe the problem ist the file extension "img2.jog".  Should be jpg.

Gustavo Farias Veloso Carvalho

unread,
Aug 13, 2021, 7:34:18 AM8/13/21
to Keycloak User
Good morning Tobias, how are you?
Thank you very much for your attention my friend.

The .jog file was a typo when I was posting the message on the forum lol
I checked the code and it really is .jpg hahahaha

Gustavo Farias Veloso Carvalho

unread,
Aug 13, 2021, 9:43:03 AM8/13/21
to Keycloak User
I found out where the problem is, as I'm using the html directory, I can't use ftl like this: <#ftl output_format="plainText">${msg("passwordResetBody",link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration))} that would be the text form.
So I corrected it this way and it worked: ${kcSanitize(msg("passwordResetBodyHtml",link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration)))?no_esc}
Thank you guys, cyya :)

Agustin Contreras

unread,
Jul 27, 2022, 12:49:12 PM7/27/22
to Keycloak User
Hi! I'm facing the same problem. If i put the <img> with an external link in the SRC attribute, I can't set the email theme in Keycloak. How did you add the <img> tag?
My password-reset.ftl looks like this:
<html>
<body>
<div>
    <img src="https://(external link)" alt="Logo">
</div>
${kcSanitize(msg("passwordResetBodyHtml",link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration)))?no_esc}
</body>
</html>

I hope you can help me. Thanks!

Reply all
Reply to author
Forward
0 new messages