stale-tiger-66317
01/23/2025, 3:29 PMbrief-egg-61061
01/23/2025, 3:29 PMbrief-egg-61061
01/23/2025, 3:30 PMyaml courier: delivery_strategy: http http: request_config: url: <https://api.mailtrap.io/api/send> method: POST body: <base64://ZnVuY3Rpb24oY3R4KSB7CiAgcmVjaXBpZW50OiBjdHgucmVjaXBpZW50LAogIHN1YmplY3Q6IGN0eC50ZW1wbGF0ZV9kYXRhLnN1YmplY3QsCiAgdGV4dDogY3R4LnRlbXBsYXRlX2RhdGEuYm9keSwKICBodG1sOiBjdHgudGVtcGxhdGVfZGF0YS5ib2R5Cn0>= headers: Content-Type: application/json Api-Token: your_mailtrap_api_token
The body
field contains a base64-encoded Jsonnet template. When decoded, it looks like this: jsonnet function(ctx) { recipient: ctx.recipient, subject: ctx.template_data.subject, text: ctx.template_data.body, html: ctx.template_data.body }
This template creates a JSON object that Mailtrap.io's API expects. You can customize this template to match the exact structure required by Mailtrap.io's API. 4. To apply this configuration, you need to update your Ory Identities configuration. You can do this using the Ory CLI or the Ory Console as described in the [Send emails using an HTTP server](https://www.ory.sh/docs/kratos/emails-sms/sending-emails-smtp#send-emails-using-an-http-server) documentation. Remember that the exact structure of the JSON payload might vary depending on Mailtrap.io's API requirements. You may need to adjust the Jsonnet template accordingly. Also, note that you can't use URLs to load templates in Ory Network. You must use base64-encoded templates as shown in the example above. [Custom email templates](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#using-custom-message-templates) documentation provides more information on how to customize the content of the verification email itself.stale-tiger-66317
01/23/2025, 3:36 PM{
"from": {
"email": "<mailto:no-reply@warrantify.me|no-reply@warrantify.me>",
"name": "<http://Warrantify.me|Warrantify.me>"
},
"to": [
{
"email": "<Email Recipient Goes Here>"
}
],
"subject": "Email Subject Goes Here",
"html": "<Email Body Goes Here>"
}
Please generate appropriate jsonnet format to be used it with courier as httpstale-tiger-66317
01/23/2025, 3:36 PM{
"from": {
"email": "<mailto:no-reply@warrantify.me|no-reply@warrantify.me>",
"name": "<http://Warrantify.me|Warrantify.me>"
},
"to": [
{
"email": "<Email Recipient Goes Here>"
}
],
"subject": "Email Subject Goes Here",
"html": "<Email Body Goes Here>"
}
Please generate appropriate jsonnet format to be used it with courier as httpbrief-egg-61061
01/23/2025, 3:36 PMbrief-egg-61061
01/23/2025, 3:37 PMjsonnet function(ctx) { from: { email: "<mailto:no-reply@warrantify.me|no-reply@warrantify.me>", name: "<http://Warrantify.me|Warrantify.me>" }, to: [ { email: ctx.recipient } ], subject: ctx.template_data.subject, html: ctx.template_data.body }
This Jsonnet template will generate the JSON structure that your email service provider expects. To use this with the HTTP courier in Ory Kratos, you need to encode it in base64 and include it in your configuration. Here's how you can set it up: 1. Encode the Jsonnet template to base64: echo 'function(ctx) { from: { email: "<mailto:no-reply@warrantify.me|no-reply@warrantify.me>", name: "<http://Warrantify.me|Warrantify.me>" }, to: [ { email: ctx.recipient } ], subject: ctx.template_data.subject, html: ctx.template_data.body }' | base64
2. Use the resulting base64 string in your Ory Kratos configuration: yaml courier: delivery_strategy: http http: request_config: url: <https://your-email-service-provider-api-url> method: POST body: <base64://ZnVuY3Rpb24oY3R4KSB7CiAgZnJvbTogewogICAgZW1haWw6ICJuby1yZXBseUB3YXJyYW50aWZ5Lm1lIiwKICAgIG5hbWU6ICJXYXJyYW50aWZ5Lm1lIgogIH0sCiAgdG86IFsKICAgIHsKICAgICAgZW1haWw6IGN0eC5yZWNpcGllbnQKICAgIH0KICBdLAogIHN1YmplY3Q6IGN0eC50ZW1wbGF0ZV9kYXRhLnN1YmplY3QsCiAgaHRtbDogY3R4LnRlbXBsYXRlX2RhdGEuYm9keQp9> headers: Content-Type: application/json # Add any other required headers for your email service provider
Make sure to replace <https://your-email-service-provider-api-url>
with the actual URL of your email service provider's API. To apply this configuration, you need to update your Ory Identities configuration using either the Ory CLI or the Ory Console, as described in the [Send emails using an HTTP server](https://www.ory.sh/docs/kratos/emails-sms/sending-emails-smtp#send-emails-using-an-http-server) documentation. Remember that you may need to adjust the Jsonnet template if your email service provider requires additional fields or has different field names. The provided template matches the structure you specified in your question. [Custom email templates](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#using-custom-message-templates) documentation provides more information on how to customize the content of the emails themselves, which will be used to populate the subject
and body
fields in this template.stale-tiger-66317
01/23/2025, 3:45 PMbrief-egg-61061
01/23/2025, 3:45 PMbrief-egg-61061
01/23/2025, 3:46 PMbody
field doesn't exist in the ctx.template_data
object. Let's modify the Jsonnet template to use the correct fields available in the context. Here's an updated version that should work:
jsonnet
function(ctx) {
from: {
email: "<mailto:no-reply@warrantify.me|no-reply@warrantify.me>",
name: "<http://Warrantify.me|Warrantify.me>"
},
to: [
{
email: ctx.recipient
}
],
subject: if "subject" in ctx.template_data then ctx.template_data.subject else "",
html: if "body" in ctx.template_data then ctx.template_data.body.html else ""
}
This template includes some error checking to prevent the "field does not exist" error. Here's what changed:
1. We're now checking if the subject
field exists in ctx.template_data
before trying to access it.
2. For the HTML content, we're checking if body
exists in ctx.template_data
, and then accessing the html
property within it.
To use this updated template:
1. Encode it to base64:
echo 'function(ctx) {
from: {
email: "<mailto:no-reply@warrantify.me|no-reply@warrantify.me>",
name: "<http://Warrantify.me|Warrantify.me>"
},
to: [
{
email: ctx.recipient
}
],
subject: if "subject" in ctx.template_data then ctx.template_data.subject else "",
html: if "body" in ctx.template_data then ctx.template_data.body.html else ""
}' | base64
2. Use the resulting base64 string in your Ory Kratos configuration:
yaml
courier:
delivery_strategy: http
http:
request_config:
url: <https://your-email-service-provider-api-url>
method: POST
body: <base64://ZnVuY3Rpb24oY3R4KSB7CiAgZnJvbTogewogICAgZW1haWw6ICJuby1yZXBseUB3YXJyYW50aWZ5Lm1lIiwKICAgIG5hbWU6ICJXYXJyYW50aWZ5Lm1lIgogIH0sCiAgdG86IFsKICAgIHsKICAgICAgZW1haWw6IGN0eC5yZWNpcGllbnQKICAgIH0KICBdLAogIHN1YmplY3Q6IGlmICJzdWJqZWN0IiBpbiBjdHgudGVtcGxhdGVfZGF0YSB0aGVuIGN0eC50ZW1wbGF0ZV9kYXRhLnN1YmplY3QgZWxzZSAiIiwKICBodG1sOiBpZiAiYm9keSIgaW4gY3R4LnRlbXBsYXRlX2RhdGEgdGhlbiBjdHgudGVtcGxhdGVfZGF0YS5ib2R5Lmh0bWwgZWxzZSAiIgp9>
headers:
Content-Type: application/json
# Add any other required headers for your email service provider
This updated template should resolve the "field does not exist: body" error. If you're still encountering issues, you might want to check the exact structure of the ctx
object that Ory Kratos is passing to the template. You can do this by adding some debug output to your template, like this:
jsonnet
function(ctx) {
debug: std.trace(std.toString(ctx), "Context:"),
// ... rest of your template
}
This will print the entire context object to the logs, which can help you understand what fields are available and how to access them correctly.brief-egg-61061
01/23/2025, 3:46 PMbody
field doesn't exist in the ctx.template_data
object. Let's modify the Jsonnet template to use the correct fields available in the context. Here's an updated version that should work: jsonnet function(ctx) { from: { email: "<mailto:no-reply@warrantify.me|no-reply@warrantify.me>", name: "<http://Warrantify.me|Warrantify.me>" }, to: [ { email: ctx.recipient } ], subject: if "subject" in ctx.template_data then ctx.template_data.subject else "", html: if "body" in ctx.template_data then ctx.template_data.body.html else "" }
This template includes some error checking to prevent the "field does not exist" error. Here's what changed: 1. We're now checking if the subject
field exists in ctx.template_data
before trying to access it. 2. For the HTML content, we're checking if body
exists in ctx.template_data
, and then accessing the html
property within it. To use this updated template: 1. Encode it to base64: echo 'function(ctx) { from: { email: "<mailto:no-reply@warrantify.me|no-reply@warrantify.me>", name: "<http://Warrantify.me|Warrantify.me>" }, to: [ { email: ctx.recipient } ], subject: if "subject" in ctx.template_data then ctx.template_data.subject else "", html: if "body" in ctx.template_data then ctx.template_data.body.html else "" }' | base64
2. Use the resulting base64 string in your Ory Kratos configuration: yaml courier: delivery_strategy: http http: request_config: url: <https://your-email-service-provider-api-url> method: POST body: <base64://ZnVuY3Rpb24oY3R4KSB7CiAgZnJvbTogewogICAgZW1haWw6ICJuby1yZXBseUB3YXJyYW50aWZ5Lm1lIiwKICAgIG5hbWU6ICJXYXJyYW50aWZ5Lm1lIgogIH0sCiAgdG86IFsKICAgIHsKICAgICAgZW1haWw6IGN0eC5yZWNpcGllbnQKICAgIH0KICBdLAogIHN1YmplY3Q6IGlmICJzdWJqZWN0IiBpbiBjdHgudGVtcGxhdGVfZGF0YSB0aGVuIGN0eC50ZW1wbGF0ZV9kYXRhLnN1YmplY3QgZWxzZSAiIiwKICBodG1sOiBpZiAiYm9keSIgaW4gY3R4LnRlbXBsYXRlX2RhdGEgdGhlbiBjdHgudGVtcGxhdGVfZGF0YS5ib2R5Lmh0bWwgZWxzZSAiIgp9> headers: Content-Type: application/json # Add any other required headers for your email service provider
This updated template should resolve the "field does not exist: body" error. If you're still encountering issues, you might want to check the exact structure of the ctx
object that Ory Kratos is passing to the template. You can do this by adding some debug output to your template, like this: jsonnet function(ctx) { debug: std.trace(std.toString(ctx), "Context:"), // ... rest of your template }
This will print the entire context object to the logs, which can help you understand what fields are available and how to access them correctly. For more information on customizing email templates and troubleshooting, you can refer to the [Custom email templates](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#using-custom-message-templates) and [Troubleshooting](https://www.ory.sh/docs/kratos/emails-sms/sending-emails-smtp#troubleshooting) sections of the Ory documentation.stale-tiger-66317
01/23/2025, 6:15 PMstale-tiger-66317
01/23/2025, 6:45 PMbrief-egg-61061
01/23/2025, 6:45 PMbrief-egg-61061
01/23/2025, 6:46 PMjsonnet function(ctx) { from: { email: "<mailto:no-reply@example.com|no-reply@example.com>", name: "Your Company Name" }, to: [ { email: ctx.recipient } ], subject: if "subject" in ctx.template_data then ctx.template_data.subject else "", html: if "body" in ctx.template_data then ctx.template_data.body.html else "" }
2. After creating your Jsonnet template, you need to encode it to base64 and include it in your Ory Kratos configuration. Here's an example of how your configuration might look: yaml courier: delivery_strategy: http http: request_config: url: <https://your-email-service-provider-api-url> method: POST body: <base64://ZnVuY3Rpb24oY3R4KSB7CiAgZnJvbTogewogICAgZW1haWw6ICJuby1yZXBseUBleGFtcGxlLmNvbSIsCiAgICBuYW1lOiAiWW91ciBDb21wYW55IE5hbWUiCiAgfSwKICB0bzogWwogICAgewogICAgICBlbWFpbDogY3R4LnJlY2lwaWVudAogICAgfQogIF0sCiAgc3ViamVjdDogaWYgInN1YmplY3QiIGluIGN0eC50ZW1wbGF0ZV9kYXRhIHRoZW4gY3R4LnRlbXBsYXRlX2RhdGEuc3ViamVjdCBlbHNlICIiLAogIGh0bWw6IGlmICJib2R5IiBpbiBjdHgudGVtcGxhdGVfZGF0YSB0aGVuIGN0eC50ZW1wbGF0ZV9kYXRhLmJvZHkuaHRtbCBlbHNlICIiCn0>= headers: Content-Type: application/json
The "from" value is now included directly in the Jsonnet template, which is then base64 encoded and used in the configuration. To apply this configuration, you need to update your Ory Identities configuration using either the Ory CLI or the Ory Console, as described in the [Send emails using an HTTP server](https://www.ory.sh/docs/kratos/emails-sms/sending-emails-smtp#send-emails-using-an-http-server) documentation. Remember that the exact structure of the JSON payload might vary depending on your email service provider's API requirements. You may need to adjust the Jsonnet template accordingly. [Custom email templates](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#using-custom-message-templates) documentation provides more information on how to customize the content of the emails themselves.