incalculable-petabyte-84501
03/27/2025, 2:50 PMTo
https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates
however Hello {{ .To }},
results in Hello ,
on receiving the mailbrief-egg-61061
03/27/2025, 2:50 PMbrief-egg-61061
03/27/2025, 2:50 PM.To
variable should be available in email templates. Looking at the issue you're experiencing, there seems to be a discrepancy between what's documented and what's actually available in your template. According to the documentation, the .To
variable should be available in verification templates. For the verification_code.valid
or verification.valid
templates (depending on whether you're using code or link verification), the following variables are available: | Variable | Description | | --- | --- | | To
| the email address the email will be sent to | | VerificationCode
or VerificationURL
| the verification code or link | | Identity
| the identity of the email address | [Email templates documentation](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#available-variables) Since you're not getting a value for .To
, you might want to try accessing the email through the identity object instead. The email address should be available in the identity traits or verifiable addresses. Try one of these approaches: Hello {{ .Identity.traits.email }},
Or if your email field has a different name in your identity schema: Hello {{ index .Identity.traits "your_email_field_name" }},
Or you could try accessing it through the verifiable addresses: Hello {{ (index .Identity.verifiable_addresses 0).value }},
The exact path depends on your identity schema structure. You can also try printing the entire identity object to see its structure: {{ printf "%+v" .Identity }}
This will help you understand what data is available in your template and how to access it correctly.incalculable-petabyte-84501
03/27/2025, 2:55 PM{{ printf "%+v" .Identity }} {{ printf "%+v" .To }}
into the template the result is:
<nil> <nil>brief-egg-61061
03/27/2025, 2:55 PMbrief-egg-61061
03/27/2025, 2:55 PM.Identity
and .To
variables are returning <nil>
in your template, which indicates they're not being populated correctly. This is unexpected based on the documentation. Let's look at some possible solutions: 1. Check your template location and naming: Make sure your template files are in the correct location and follow the proper naming convention. For verification templates, they should be in paths like verification/valid/email.body.gotmpl
or verification_code/valid/email.body.gotmpl
depending on your verification method. 2. Try accessing the transient payload: If you're passing data through a transient payload, you might be able to access it: {{ printf "%+v" .TransientPayload }}
3. Check template data in logs: Enable debug logging to see what data is actually being passed to the template. 4. Use HTTP-based email delivery: If you're self-hosting, you could try switching to HTTP-based email delivery which gives you more control and visibility into the template data: yaml courier: delivery_strategy: http http: request_config: url: <https://your-api.com/email> method: POST body: <file://path/to/template.jsonnet>
[HTTP based email delivery](https://www.ory.sh/docs/kratos/self-hosted/email-http#configuration) 5. Check for recent issues: This might be a bug in the current version of Ory Kratos. There's an open GitHub issue (#4161) that mentions verification emails being sent when they shouldn't be, which could be related to your issue. If none of these approaches work, you might need to use a workaround by hardcoding the email address in your template or using a custom email delivery solution that gives you more control over the template variables. Could you also share which version of Ory Kratos you're using and whether you're self-hosting or using Ory Network? That might help narrow down the issue.