<@U04UQ68083H>, we have configured the courier to ...
# ory-copilot
f
@chilly-king-10285, we have configured the courier to send email templates using the http delivery strategy but noticed that the HTML templates are not available within the jsonnet context by default. Is there a way how we could load the HTML templates within the request body? It looks like the HTML template is only received within the smtp delivery strategy: https://github.com/ory/kratos/blob/253c5b67278939974a80d8ba2c8636268da89da2/courier/smtp_channel.go#L103
b
A message from kapa.ai
To answer your question about loading HTML templates within the request body when using the HTTP delivery strategy for email templates in Ory Kratos, I'll need to provide some context and clarification based on the available information. You're correct that the HTML templates are not directly available within the Jsonnet context by default when using the HTTP delivery strategy. This is different from the SMTP delivery strategy, where the HTML template is indeed processed as you've pointed out in the GitHub link. For the HTTP delivery strategy, Ory Kratos provides a different approach. According to the [HTTP based email delivery documentation](https://www.ory.sh/docs/kratos/self-hosted/email-http), you can customize the request body using a Jsonnet template. However, this template doesn't automatically include the rendered HTML content. To include the HTML content in your HTTP request, you would need to modify your Jsonnet template to include both the plaintext and HTML versions of the email. Here's how you might approach this: 1. First, ensure that you have both plaintext and HTML versions of your email templates configured. As mentioned in the [Mandatory template formats documentation](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats), each template must have both versions. 2. In your Jsonnet template for the HTTP request body, you can access the rendered plaintext content through
ctx.body
. However, there isn't a direct way to access the rendered HTML content. 3. One potential workaround would be to include both the plaintext and HTML versions in your template configuration, and then access them in your Jsonnet template. For example:
Copy code
jsonnet
function(ctx) {
  recipient: ctx.recipient,
  template_type: ctx.template_type,
  body: {
    plaintext: ctx.body,
    html: if "template_data" in ctx && "body" in ctx.template_data then ctx.template_data.body.html else null
  }
}
This approach assumes that the HTML content is available in
ctx.template_data.body.html
, which may not be the case by default. Unfortunately, based on the provided knowledge sources, there isn't a straightforward way to load the HTML templates within the request body when using the HTTP delivery strategy. The current implementation seems to focus on providing the plaintext version through the Jsonnet context. If you need to include the HTML version in your HTTP requests, you might need to consider one of these options: 1. Modify the Ory Kratos source code to include the HTML version in the Jsonnet context for HTTP delivery. 2. Use the SMTP delivery strategy instead, which does process the HTML templates. 3. Create a custom HTTP endpoint that receives the plaintext version and generates an HTML version based on your requirements.
To answer your question about loading HTML templates within the request body when using the HTTP delivery strategy for email templates in Ory Kratos, I'll need to provide some context and clarification based on the available information. You're correct that the HTML templates are not directly available within the Jsonnet context by default when using the HTTP delivery strategy. This is different from the SMTP delivery strategy, where the HTML template is indeed processed as you've pointed out in the GitHub link. For the HTTP delivery strategy, Ory Kratos provides a different approach. According to the [HTTP based email delivery documentation](https://www.ory.sh/docs/kratos/self-hosted/email-http), you can customize the request body using a Jsonnet template. However, this template doesn't automatically include the rendered HTML content. To include the HTML content in your HTTP request, you would need to modify your Jsonnet template to include both the plaintext and HTML versions of the email. Here's how you might approach this: 1. First, ensure that you have both plaintext and HTML versions of your email templates configured. As mentioned in the [Mandatory template formats documentation](https://www.ory.sh/docs/kratos/emails-sms/custom-email-templates#mandatory-template-formats), each template must have both versions. 2. In your Jsonnet template for the HTTP request body, you can access the rendered plaintext content through
ctx.body
. However, there isn't a direct way to access the rendered HTML content. 3. One potential workaround would be to include both the plaintext and HTML versions in your template configuration, and then access them in your Jsonnet template. For example:
Copy code
jsonnet function(ctx) {   recipient: ctx.recipient,   template_type: ctx.template_type,   body: {     plaintext: ctx.body,     html: if "template_data" in ctx && "body" in ctx.template_data then ctx.template_data.body.html else null   } }
This approach assumes that the HTML content is available in
ctx.template_data.body.html
, which may not be the case by default. Unfortunately, based on the provided knowledge sources, there isn't a straightforward way to load the HTML templates within the request body when using the HTTP delivery strategy. The current implementation seems to focus on providing the plaintext version through the Jsonnet context. If you need to include the HTML version in your HTTP requests, you might need to consider one of these options: 1. Modify the Ory Kratos source code to include the HTML version in the Jsonnet context for HTTP delivery. 2. Use the SMTP delivery strategy instead, which does process the HTML templates. 3. Create a custom HTTP endpoint that receives the plaintext version and generates an HTML version based on your requirements. For the most up-to-date and accurate information on this topic, I recommend reaching out to the Ory community or opening an issue on the [Ory Kratos GitHub repository](https://github.com/ory/kratos) to discuss potential solutions or feature requests.