https://www.ory.sh/ logo
#talk-kratos
Title
# talk-kratos
s

stocky-pager-63161

12/17/2021, 10:42 AM
Hi all, a quick question about email templates: why are both plain text and html templates required? where do we specify which one to use? cant find anything in docs related to this, it only says: "corresponding to the respective methods for filling e-mail subject and body"
m

magnificent-energy-493

12/17/2021, 11:11 AM
text/template
package for rendering the
email.subject.gotmpl
and
email.body.plaintext.gotmpl
templates &
html/template
package for rendering the
email.body.gotmpl
template So you get subject and plain text version with text/template and the HTML body with the html/template package.
I think you need both if the email client does not support HTML it will display the plain-text version.
b

bitter-arm-6486

12/17/2021, 11:25 AM
I see so kratos handles these automatically? If we want to support i18n we have to provide two sets of templates? @magnificent-energy-493
As far as I understand when you mention package you mean in the kratos go source code right? It is not controllable by clients?
Follow up
m

magnificent-energy-493

12/17/2021, 12:04 PM
Hey Kevin, for i18n check out this document: https://www.ory.sh/kratos/docs/concepts/email-sms/#nested-templates
b

bitter-arm-6486

12/17/2021, 12:19 PM
The doc only mentions the non plain text variant. I want to clarify if both sets of templates are expected
m

magnificent-energy-493

12/17/2021, 12:50 PM
Yea, apologies I am not 100% sure at the moment as well. I will see if someone from the team has more experience there.
👍 1
b

bitter-arm-6486

12/17/2021, 1:00 PM
Thanks @magnificent-energy-493 !
@magnificent-energy-493 any further updates on this topic?
m

magnificent-energy-493

12/20/2021, 3:05 PM
Sorry I dont have a good answer yet, made a note to follow you up on this.
👍 1
b

bitter-arm-6486

12/20/2021, 3:08 PM
Thanks, I looked briefly into the code base for kratos and it doesn't really make sense. QueueEmail uses plaintext while dispatchEmail uses the html variant. These two functions as far as I can see don't interact with each other, but it can't possibly be random.
Definitely hoping to get this clarified and I'm happy to update docs if we find a firm answer
👍 1
Looking to clarify this as well before the holidays! Thanks
m

magnificent-energy-493

12/23/2021, 6:16 PM
it seems you need both the plain text and html. The courier uses them as alternatives for fallback
// AddAlternative adds an alternative part to the message.
//
// It is commonly used to send HTML emails that default to the plain text
// version for backward compatibility. AddAlternative appends the new part to
// the end of the message. So the plain text part should be added before the
// HTML part. See http://en.wikipedia.org/wiki/MIME#Alternative
https://github.com/ory/kratos/blob/1762a730886707be3549bc6789f65c66d755e1d0/courier/courier.go#L205
👍 1
b

bitter-arm-6486

12/23/2021, 6:41 PM
Thanks
Hey @magnificent-energy-493 I can confirm after testing that mailing client will default to plaintext if the html version throws any errors. As such, seems to me like since only html version supports templating, translating the plaintext emails is useless as we cannot dynamically switch between them. If the email with html template fails to send it will be sent as plaintext with some default language. This is the current intended behaviour right?
2 Views