<@U04UQ68083H> ory kratos, how can i change the co...
# ory-copilot
s
@chilly-king-10285 ory kratos, how can i change the content body of verification email?
b
A message from kapa.ai
To change the content body of the verification email in Ory Kratos, you need to customize the email templates used for the verification flow. The process depends on whether you are using Ory Network or self-hosting Ory Kratos. --- ### For Self-hosted Ory Kratos 1. Template Location: Place your custom templates in the directory specified by
template_override_path
in your Kratos config, or configure them directly in the
courier.templates
section. The system expects templates at paths like: -
<kratos-root>/<template-root>/verification/valid/email.body.gotmpl
(HTML) -
<kratos-root>/<template-root>/verification/valid/email.body.plaintext.gotmpl
(Plaintext) 2. Config Example:
Copy code
yaml    courier:      template_override_path: /conf/courier-template      templates:        verification:          valid:            email:              body:                html: file:///conf/courier-template/verification/valid/email.body.gotmpl                plaintext: file:///conf/courier-template/verification/valid/email.body.plaintext.gotmpl
Both
html
and
plaintext
versions are required. You can also use
base64://
or
http://
URIs for the template content. 3. Template Content Example: - HTML (
email.body.gotmpl
):
Copy code
html      Hi, please verify your account by clicking the following link:<br>      <a href="{{ .VerificationURL }}">{{ .VerificationURL }}</a>
- Plaintext (
email.body.plaintext.gotmpl
):
Copy code
Hi, please verify your account by clicking the following link: {{ .VerificationURL }}
4. Reload Kratos: After updating the templates, restart your Kratos instance to apply the changes. For more details, see the documentation on [self-hosted email templates](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates) and [mandatory template formats](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats). --- ### For Ory Network 1. Encode Your Template: Encode your custom template content in base64. 2. Update Configuration: Add the base64-encoded template to your project config under the appropriate section:
Copy code
yaml    courier:      smtp:        templates:          verification:            valid:              email:                body:                  html: "<base64://ENCODED_HTML_TEMPLATE>"                  plaintext: "<base64://ENCODED_PLAINTEXT_TEMPLATE>"
3. Upload the Config: Use the Ory CLI to upload your updated configuration:
Copy code
ory update identity-config --project <project-id> --workspace <workspace-id> --file updated_config.yaml
For more, see the [custom email templates guide](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#using-custom-message-templates). --- Note: - Both HTML and plaintext versions are required. - You can use template variables like
{{ .VerificationURL }}
in your templates. - For internationalization or user-specific customization, see the [i18n and identity-based customization section](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#customizing-template-content-for-specific-users). --- References: - [Self-hosted email templates](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates) - [Custom email templates](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#using-custom-message-templates) - [Mandatory template formats](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats)
s
@chilly-king-10285 this is my config, but it did not work courier: template_override_path: /etc/config/kratos/templates templates: verification: valid: email: body: html: base64://PGgxPldlbGNvbWUgdG8gTWluaXN0ZXIgRGFzaGJvYXJkITwvaDE+PHA+UGxlYXNlIHZlcmlmeSB5b3VyIGFjY291bnQgYnkgZW50ZXJpbmcgdGhlIGZvbGxvd2luZyBjb2RlOjwvcD48aDI+e3sgLkNvZGUgfX08L2gyPjxwPm9yIGNsaWNraW5nIHRoZSBmb2xsb3dpbmcgbGluazo8L3A+PHA+PGEgaHJlZj0ie3sgLlVSTCB9fSI+VmVyaWZ5IEVtYWlsIEFkZHJlc3M8L2E+PC9wPjxwPklmIHlvdSBkaWQgbm90IHJlcXVlc3QgdGhpcyB2ZXJpZmljYXRpb24sIHBsZWFzZSBpZ25vcmUgdGhpcyBlbWFpbC48L3A+ plaintext: base64://SGksCgpwbGVhc2UgdmVyaWZ5IHlvdXIgYWNjb3VudCBieSBlbnRlcmluZyB0aGUgZm9sbG93aW5nIGNvZGU6Cgp7eyAuQ29kZSB9fQoKb3IgY2xpY2tpbmcgdGhlIGZvbGxvd2luZyBsaW5rOgoKe3sgLlVSTCB9fQ== subject: base64://VmVyaWZ5IHlvdXIgZW1haWwgYWRkcmVzcyBmb3IgTWluaXN0ZXIgRGFzaGJvYXJk invalid: email: body: html: base64://PCFkb2N0eXBlIGh0bWw+PGh0bWw+PGhlYWQ+PG1ldGEgY2hhcnNldD0iVVRGLTgiPjx0aXRsZT5JbnZhbGlkIFZlcmlmaWNhdGlvbiBSZXF1ZXN0PC90aXRsZT48L2hlYWQ+PGJvZHk+PGgxPkludmFsaWQgVmVyaWZpY2F0aW9uIFJlcXVlc3Q8L2gxPjxwPlRoZSB2ZXJpZmljYXRpb24gcmVxdWVzdCB5b3UgcmVjZWl2ZWQgaXMgbm8gbG9uZ2VyIHZhbGlkLjwvcD48cD5JZiB5b3UgbmVlZCB0byB2ZXJpZnkgeW91ciBlbWFpbCBhZGRyZXNzLCBwbGVhc2UgcmVxdWVzdCBhIG5ldyB2ZXJpZmljYXRpb24gZW1haWwuPC9wPjwvYm9keT48L2h0bWw+ plaintext: base64://SW52YWxpZCBWZXJpZmljYXRpb24gUmVxdWVzdAoKVGhlIHZlcmlmaWNhdGlvbiByZXF1ZXN0IHlvdSByZWNlaXZlZCBpcyBubyBsb25nZXIgdmFsaWQuCgpJZiB5b3UgbmVlZCB0byB2ZXJpZnkgeW91ciBlbWFpbCBhZGRyZXNzLCBwbGVhc2UgcmVxdWVzdCBhIG5ldyB2ZXJpZmljYXRpb24gZW1haWwu subject: base64://SW52YWxpZCBWZXJpZmljYXRpb24gUmVxdWVzdA== smtp: connection_uri: smtp://md-delete-mailhog-1:1025/?skip_ssl_verify=true&amp;disable_starttls=true from_address: noreply_dev_md@vnsilicon.net from_name: Test Minister Dashboard
b
A message from kapa.ai
s
@chilly-king-10285 this is my config, but it did not work
Copy code
courier:
  template_override_path: /etc/config/kratos/templates
  templates:
    verification:
      valid:
        email:
          body:
            html: <base64://PGgxPldlbGNvbWUgdG8gTWluaXN0ZXIgRGFzaGJvYXJkITwvaDE>+PHA+UGxlYXNlIHZlcmlmeSB5b3VyIGFjY291bnQgYnkgZW50ZXJpbmcgdGhlIGZvbGxvd2luZyBjb2RlOjwvcD48aDI+e3sgLkNvZGUgfX08L2gyPjxwPm9yIGNsaWNraW5nIHRoZSBmb2xsb3dpbmcgbGluazo8L3A+PHA+PGEgaHJlZj0ie3sgLlVSTCB9fSI+VmVyaWZ5IEVtYWlsIEFkZHJlc3M8L2E+PC9wPjxwPklmIHlvdSBkaWQgbm90IHJlcXVlc3QgdGhpcyB2ZXJpZmljYXRpb24sIHBsZWFzZSBpZ25vcmUgdGhpcyBlbWFpbC48L3A+
            plaintext: <base64://SGksCgpwbGVhc2UgdmVyaWZ5IHlvdXIgYWNjb3VudCBieSBlbnRlcmluZyB0aGU>gZm9sbG93aW5nIGNvZGU6Cgp7eyAuQ29kZSB9fQoKb3IgY2xpY2tpbmcgdGhlIGZvbGxvd2luZyBsaW5rOgoKe3sgLlVSTCB9fQ==
          subject: <base64://VmVyaWZ5IHlvdXIgZW1haWwgYWRkcmVzcyBmb3IgTWluaXN0ZXIgRGFzaGJvYXJ>k
      invalid:
        email:
          body:
            html: <base64://PCFkb2N0eXBlIGh0bWw>+PGh0bWw+PGhlYWQ+PG1ldGEgY2hhcnNldD0iVVRGLTgiPjx0aXRsZT5JbnZhbGlkIFZlcmlmaWNhdGlvbiBSZXF1ZXN0PC90aXRsZT48L2hlYWQ+PGJvZHk+PGgxPkludmFsaWQgVmVyaWZpY2F0aW9uIFJlcXVlc3Q8L2gxPjxwPlRoZSB2ZXJpZmljYXRpb24gcmVxdWVzdCB5b3UgcmVjZWl2ZWQgaXMgbm8gbG9uZ2VyIHZhbGlkLjwvcD48cD5JZiB5b3UgbmVlZCB0byB2ZXJpZnkgeW91ciBlbWFpbCBhZGRyZXNzLCBwbGVhc2UgcmVxdWVzdCBhIG5ldyB2ZXJpZmljYXRpb24gZW1haWwuPC9wPjwvYm9keT48L2h0bWw+
            plaintext: <base64://SW52YWxpZCBWZXJpZmljYXRpb24gUmVxdWVzdAoKVGhlIHZlcmlmaWNhdGlvbiB>yZXF1ZXN0IHlvdSByZWNlaXZlZCBpcyBubyBsb25nZXIgdmFsaWQuCgpJZiB5b3UgbmVlZCB0byB2ZXJpZnkgeW91ciBlbWFpbCBhZGRyZXNzLCBwbGVhc2UgcmVxdWVzdCBhIG5ldyB2ZXJpZmljYXRpb24gZW1haWwu
          subject: <base64://SW52YWxpZCBWZXJpZmljYXRpb24gUmVxdWVzdA>==
  smtp:
    connection_uri: <smtp://md-delete-mailhog-1:1025/?skip_ssl_verify=true&disable_starttls=true>
    from_address: <mailto:noreply_dev_md@vnsilicon.net|noreply_dev_md@vnsilicon.net>
    from_name: Test Minister Dashboard
b
A message from kapa.ai
Based on your provided configuration, here are some things to check and clarify according to the official Ory Kratos documentation: 1. Base64 Encoding and Prefix Your config uses
<base64://...>
(with angle brackets). The correct syntax is without angle brackets. It should be:
Copy code
yaml    html: <base64://PGgxPldlbGNvbWUgdG8gTWluaXN0ZXIgRGFzaGJvYXJkITwvaDE>+...
Remove the
<
and
>
characters. 2. Template File Paths If you use
template_override_path
, Kratos expects template files at specific paths, not inline base64 content. If you want to use inline base64 templates, you should not set
template_override_path
, or you should ensure both methods are not conflicting. - If you use
template_override_path
, place your template files (not base64) at:
Copy code
/etc/config/kratos/templates/verification/valid/email.body.gotmpl      /etc/config/kratos/templates/verification/valid/email.body.plaintext.gotmpl
- If you use base64 inline templates, configure them under
courier.templates
as you did, but do not set
template_override_path
unless you want file-based overrides. 3. Both HTML and Plaintext Required Both
html
and
plaintext
fields are mandatory for the email body, which you have provided correctly. 4. SMTP Configuration Your SMTP config looks fine for a development environment (Mailhog, no SSL). 5. Restart Kratos After making changes to the config or templates, you must restart your Kratos instance for changes to take effect. 6. Debugging - Check Kratos logs for errors related to template loading or email sending. - If emails are not being sent, verify the mail courier is running (with
--watch-courier
or as a separate job) [Mail courier in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-selfhosted). - If you use both
template_override_path
and inline templates, file-based templates take precedence. Summary of what to fix: - Remove angle brackets from your base64 URIs. - Decide between file-based templates (with
template_override_path
) or inline base64 templates, not both at the same time. - Ensure you restart Kratos after changes. References: - [Email templates in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates) - [Mandatory template formats](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats) - [Mail courier in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-selfhosted) If you still have issues after these changes, please provide any error messages from the Kratos logs for further troubleshooting.
Sorry @square-napkin-92357, I'm currently experiencing some technical difficulties. Please try again in a few minutes. If this issue persists, please reach out to the administrators of this Slack workspace.