<@U04UQ68083H> Can I load an email template via ht...
# ory-copilot
p
@chilly-king-10285 Can I load an email template via https? does it need to be base64?
b
A message from kapa.ai
For Ory Network (Ory Cloud), you cannot load email templates via an HTTPS (https://) URL. The system only supports templates provided as Base64-encoded strings. If you attempt to use a remote URL (such as an S3 bucket or GitHub), you will receive an error stating that URLs are not allowed for email templates. The correct approach is to encode your template in Base64 and use the base64:// prefix in your configuration. This applies to both the HTML and plaintext versions of the template, as well as the subject if customized. Loading templates from URLs is not supported due to security concerns [Custom email templates don't allow URLs](https://github.com/ory/network/issues/115) [Using custom message templates](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#using-custom-message-templates). In self-hosted Ory Kratos, you have more flexibility: you can load templates from base64://, file://, or http(s):// URIs. However, this is not possible in Ory Network (Ory Cloud) [Email templates in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates). Summary: - Ory Network (Cloud): Only base64-encoded templates are supported. - Self-hosted Ory Kratos: base64://, file://, and http(s):// are supported. If you are using Ory Network, you must use Base64 encoding for your email templates.
p
I have a local kratos instance.
@chilly-king-10285 I have a local kratos instance.
b
A message from kapa.ai
If you are running a local (self-hosted) Ory Kratos instance, you can load email templates via HTTPS (https://), as well as from file:// and base64:// URIs. This means you do not need to use base64 encoding specifically—loading templates directly from an HTTPS URL is supported in self-hosted mode. Here’s an example from the documentation:
Copy code
yaml courier:     template_override_path: /conf/courier-template     templates:       verification:         valid:           email:             body:               html: <https://some-remote-resource/gotmpl>               plaintext: <base64://SGV5IHlvdSBkZWNvZGVkIG1lIDop>             subject: <file://some-file/subject.gotmpl>
Both the
html
and
plaintext
fields are mandatory when defining the
body
key. If the system can't use the custom templates, it will fall back to the built-in templates or to the
template_override_path
if specified [Email templates in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates). Summary: - In self-hosted Ory Kratos, you can load email templates via https://, file://, or base64://. - Base64 encoding is not required unless you prefer it or are using Ory Network (Cloud).
p
@chilly-king-10285 I have that in my config but courier is not using my template. How to debug this?
b
A message from kapa.ai
If your self-hosted Ory Kratos instance is not using your custom email template, here are some steps and considerations for debugging, based on the official documentation: 1. Template Paths and Configuration - Ensure your config uses the correct structure and that both
html
and
plaintext
fields are set under the
body
key. - If you use a remote URL (https://), make sure the URL is accessible from your Kratos instance and returns the expected template content. - The
template_override_path
should point to the correct directory if you are using local files. The expected structure is: -
<kratos-root>/<template-root>/recovery/valid
-
<kratos-root>/<template-root>/verification/valid
- etc. - If the system can't use the custom templates, it will fall back to built-in templates or the
template_override_path
if specified [Email templates in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates). 2. File Permissions and Accessibility - If using file-based templates, ensure the Kratos process has read permissions for the template files. 3. Template Format - Both
html
and
plaintext
versions are mandatory. If either is missing or invalid, the template may be ignored [Mandatory template formats](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats). 4. Restart Kratos - After changing templates or configuration, restart your Kratos instance to ensure changes are loaded. 5. Logs and Error Messages - Check Kratos logs for any errors or warnings related to template loading or email delivery. Errors here can indicate missing files, permission issues, or template parsing problems. 6. Testing Template Override - Try using a simple template to rule out syntax errors. For example, set the plaintext template to a simple string and see if it appears in the email. 7. Multiple Instances - If running multiple Kratos or courier instances, ensure all have access to the templates [Mail courier in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-selfhosted). If after these steps your template is still not used, double-check the config structure and paths, and consult the logs for specific error messages. If you need more detailed troubleshooting, please provide relevant log output or error messages. If you want to view outgoing messages and their status, you can also check the Email Delivery page in the Ory Console if you are using Ory Network, but for self-hosted, rely on your local logs [Use a custom server to send Ory Identity messages to users](https://www.ory.sh/docs/kratos/emails-sms/sending-emails-smtp#troubleshooting).
p
@chilly-king-10285 How do I speficy the verification code valie email template path?
b
A message from kapa.ai
To specify the verification code valid email template path in a self-hosted Ory Kratos instance, you need to configure the
courier.templates.verification_code.valid.email.body
section in your configuration file. You can provide the template using a
file://
,
http(s)://
, or
base64://
URI. Both
html
and
plaintext
fields are required. Here’s an example configuration:
Copy code
yaml courier:   templates:     verification_code:       valid:         email:           body:             html: file:///path/to/your/verification_code_valid_email.body.gotmpl             plaintext: file:///path/to/your/verification_code_valid_email.body.plaintext.gotmpl
Or, if you want to use an HTTPS URL for the HTML template:
Copy code
yaml courier:   templates:     verification_code:       valid:         email:           body:             html: <https://your-domain.com/templates/verification_code_valid_email.body.gotmpl>             plaintext: file:///path/to/your/verification_code_valid_email.body.plaintext.gotmpl
Make sure both files exist and are accessible by the Kratos process. If the templates are not found or not valid, Kratos will fall back to the built-in templates or the
template_override_path
if specified [Email templates in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates). Note: - The
verification_code.valid
template is used when the verification method is set to "code" [Available variables](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#available-variables). - Both
html
and
plaintext
versions are mandatory [Mandatory template formats](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats). If you use a
template_override_path
, the expected directory structure is:
Copy code
<template-root>/verification_code/valid/email.body.gotmpl <template-root>/verification_code/valid/email.body.plaintext.gotmpl
This allows Kratos to locate your custom templates automatically [Email templates in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates).
p
@chilly-king-10285 I believe I have everything setup and yet my templates are not being used. Hte files are readable in the kratos pod and kratos-courier pod. My config is below. How can I debug this?
Copy code
courier:                                                                                          
  templates:                                                                                      
    verification_code:                                                                            
      valid:                                                                                      
        email:                                                                                    
          body:                                                                                   
            html: file:///etc/kratos/templates/verification.valid.email.body.html.gotmpl          
            plaintext: file:///etc/kratos/templates/verification.valid.email.body.plaintext.gotmpl
          subject: file:///etc/kratos/templates/verification.valid.email.subject.gotmpl
b
A message from kapa.ai
Based on your configuration and the knowledge sources, here are the key points and debugging steps: 1. Template Path and Naming Your config uses:
Copy code
verification_code:      valid:        email:          body:            html: file:///etc/kratos/templates/verification.valid.email.body.html.gotmpl            plaintext: file:///etc/kratos/templates/verification.valid.email.body.plaintext.gotmpl          subject: file:///etc/kratos/templates/verification.valid.email.subject.gotmpl
According to the documentation, the expected directory structure for self-hosted Kratos is:
Copy code
<template-root>/verification_code/valid/email.body.gotmpl    <template-root>/verification_code/valid/email.body.plaintext.gotmpl    <template-root>/verification_code/valid/email.subject.gotmpl
Your file names use
verification.valid.email.body.html.gotmpl
instead of the expected
verification_code/valid/email.body.gotmpl
. This mismatch may cause Kratos to not find your templates [Email templates in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates). 2. Template Type The config section you are using is for the
verification_code
flow, not
verification
. Make sure your flow is actually using verification by code, not by link, as the template keys differ [Email templates](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates). 3. File Accessibility You mentioned the files are readable in both pods, which is good. Double-check that the file contents are valid Go templates and that both
html
and
plaintext
are present and non-empty [Mandatory template formats](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats). 4. Logs Check the logs of both the Kratos and kratos-courier pods for any errors or warnings related to template loading or parsing. Kratos will fall back to built-in templates if it cannot load or parse your custom templates [Mail courier in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-selfhosted). 5. Restart Pods After making changes to templates or configuration, ensure you restart both the Kratos and kratos-courier pods so they reload the templates. Summary of debugging steps: - Rename your template files and directory structure to match the expected pattern:
/etc/kratos/templates/verification_code/valid/email.body.gotmpl
/etc/kratos/templates/verification_code/valid/email.body.plaintext.gotmpl
/etc/kratos/templates/verification_code/valid/email.subject.gotmpl
- Update your config to point to these files or use the
template_override_path
to set the root directory. - Check logs for errors. - Restart your pods after changes. If you follow these steps and still encounter issues, please provide any relevant log output for further assistance.
p
@chilly-king-10285 dosen't using the file:// URI mean I can put the files anywhere in the filesytem and use any name I want?
b
A message from kapa.ai
Using the
file://
URI does allow you to specify an absolute path to any file on the filesystem, and you are not required to use the default directory structure or file names. The documentation states: > In self-hosted Ory Kratos instances, you can add custom templates from
http://
,
file://
, and
base64://
URIs. The
plaintext
and
html
fields are mandatory when defining the
body
key. All other keys are optional. If the system can't use the custom templates, it falls back to the built-in templates or to the
template_override_path
(if specified) [Email templates in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates). This means you can place your template files anywhere on the filesystem and use any file name, as long as your configuration points to the correct path using the
file://
URI. The default directory structure is only required if you use the
template_override_path
mechanism, not when specifying explicit
file://
URIs in your config. If your templates are not being used, the issue is likely not with the file location or name (when using
file://
), but could be related to file permissions, template validity, or another configuration issue.
p
@chilly-king-10285 how can I validate the templates? I see nothing in the courier logs
b
A message from kapa.ai
I'm sorry, but the knowledge sources do not provide a specific method or tool for validating email templates in Ory Kratos. There is no mention of a built-in command or validation feature for templates, nor are there detailed troubleshooting steps for template syntax errors beyond checking logs for errors or warnings related to template loading or parsing [Mail courier in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-selfhosted). If you see nothing in the courier logs, the documentation suggests that Kratos will fall back to the built-in templates if it cannot load or parse your custom templates, but it does not specify how to get more detailed feedback or validation results [Email templates in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates). If you need to validate Go templates, you may need to do so outside of Ory Kratos using Go tooling or by testing with simple templates to see if they are picked up. However, this is not explicitly covered in the provided documentation.
p
@chilly-king-10285 how can I have new lines in an email template? courier seems to ignore them and pushes all my text into one line.
b
A message from kapa.ai
The knowledge sources indicate that Ory Kratos email templates use Go's
text/template
and
html/template
engines. For HTML templates (
email.body.gotmpl
), you should use HTML tags like
<br>
or
<p>
to create new lines or paragraphs, as plain newlines in the template file will not be rendered as line breaks in the resulting email. For plaintext templates (
email.body.plaintext.gotmpl
), newlines in the template file should be preserved in the sent email, as long as the receiving email client displays them as such [Mandatory template formats](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats). Example for HTML template:
Copy code
html Hello {{ .Identity.traits.firstName }},<br> Please use the following code:<br> {{ .VerificationCode }}
Example for plaintext template:
Copy code
Hello {{ .Identity.traits.firstName }},  Please use the following code: {{ .VerificationCode }}
If you are seeing all text in one line, ensure you are editing the correct template type (HTML vs. plaintext) and using the appropriate formatting for that type. If you are using an HTML template, plain newlines will not create line breaks in the rendered email; you must use
<br>
or similar HTML tags [Mandatory template formats](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats).
p
@chilly-king-10285 how does courier know to use the plaintext or html?
b
A message from kapa.ai
Ory Kratos courier uses both the
html
and
plaintext
versions of an email template when sending messages. The
html
version is used to provide rich formatting and features (like clickable links), while the
plaintext
version is used as a fallback for email clients that do not support HTML or when HTML is blocked. The documentation specifies: > Each template must have two versions:
html
and
plaintext
. > -
html
version uses the HTML syntax to achieve the desired look and functionality (such as clickable buttons) of the email message. > -
plaintext
version can't contain any HTML. Must contain only plain text content and any necessary
gotmpl
logic. This version is used as a fallback when the
html
version cannot be delivered, for example when the user's mail server blocks HTML in all incoming messages. > > [Mandatory template formats](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats) So, the courier sends both versions in the email, and the recipient's email client decides which one to display. If the client supports HTML, it will show the HTML version; otherwise, it will show the plaintext version.