Email delivery configuration
The Ory Network provides a default SMTP server for sending emails. Ory emails are sent from this address:
{project.name} via Ory <[email protected]>
To customize the sender address, sender name, and email content, you need to use your own SMTP server. This prevents abuse and ensures high deliverability rates.
Integrations
Ory's email delivery system is flexible and can be configured to work with various email service providers. Below are the connection URIs and settings for some popular email service providers.
If a provider you use is not listed here, you can still configure Ory to use it by following the instructions in the Your own server section.
Request an integration through our support channels or contribute one yourself by following the instructions on GitHub.
SendGrid
- SMTP
- HTTP
Use the following connection URI and settings to send emails using SendGrid via SMTP.
- Sender address: an email address for a domain that has been verified in SendGrid via Domain Authentication (See your available senders.)
- Port:
587 - Security Mode:
STARTTLS - Username:
apikey(constant string) - Hostname:
smtp.sendgrid.net - Password: the API key created in SendGrid, with the full “Mail Send” permission (no other permissions needed)
- SMTP Headers: none
smtp://apikey:<YOUR_SENDGRID_API_KEY>@smtp.sendgrid.net:587/
# For example:
smtp://apikey:[email protected]:587/
Use the following configuration to send emails using SendGrid via HTTP.
First, create a SendGrid API key with the "Mail Send" permission on https://app.sendgrid.com/settings/api_keys.
Then, add the following configuration to your Ory Kratos Identities configuration:
courier:
delivery_strategy: http
http:
request_config:
url: https://api.sendgrid.com/v3/mail/send
method: POST
body: base64://<base64-encoded-jsonnet>
headers:
Content-Type: application/json
auth:
type: api_key
config:
name: Authorization
value: Bearer <your-sendgrid-api-key>
in: header
The body is a Jsonnet template that turns the ctx object into a SendGrid v3 Mail Send request. Save the following
template to a file and set from to a sender verified in SendGrid:
function(ctx) {
personalizations: [
{
to: [{ email: ctx.recipient }],
},
],
from: {
email: '[email protected]',
name: 'Example',
},
subject: ctx.subject,
content: [
{ type: 'text/plain', value: ctx.body },
] + (
if std.objectHas(ctx, 'html_body') && ctx.html_body != ''
then [{ type: 'text/html', value: ctx.html_body }]
else []
),
}
On Ory Network, encode the template with Base64 and use the result in body: base64://<base64-encoded-jsonnet>:
base64 < sendgrid.jsonnet | tr -d '\n'
Self-hosted deployments can also load the template from a file, for example
body: file:///etc/config/kratos/mail.template.jsonnet.
The body: file://... Jsonnet template path is auto-discovered by the
Landlock filesystem sandbox: Kratos walks the loaded config at startup and
allow-lists every file:// URI it finds. No security.landlock.allowed_paths entry is required.
To configure SendGrid as your email provider, go to Authentication → Email Configuration in the Ory Console.
Mailgun
Use the following connection URI to send emails using Mailgun via SMTP.
Note: The username and password must be URI encoded.
smtp://{smtp-user}:{smtp-password}@smtp.mailgun.org:587
# For example:
# smtp://some-user%40mailgun.example.org:[email protected]:587
AWS SES
Use the following connection URI to send emails using AWS SES SMTP via SMTP.
Note: The username and password must be URI encoded.
smtp://{smtp-user}:{smtp-password}@email-smtp.{region}.amazonaws.com:587/
# For example:
# smtp://theuser:[email protected]:587/
Postmark
Use the following connection URI to send emails using Postmark via SMTP.
Note: The username and password must be URI encoded.
smtp://{YOUR_POSTMARK_SERVER_API_TOKEN}:{YOUR_POSTMARK_SERVER_API_TOKEN}@smtp.postmarkapp.com:587/
# For example:
# smtp://thetoken:[email protected]:587/
Brevo
Brevo (formerly Sendinblue) is a European email platform with a strong GDPR posture, commonly used when EU-hosted email infrastructure is required.
- SMTP
- HTTP
Use one of the following connection URIs to send emails using Brevo via SMTP relay:
# Port 587 with STARTTLS
smtp://<brevo-smtp-login>:<brevo-smtp-key>@smtp-relay.brevo.com:587/
# Port 465 with implicit TLS
smtps://<brevo-smtp-login>:<brevo-smtp-key>@smtp-relay.brevo.com:465/
Use the SMTP login and SMTP key shown under Brevo → SMTP & API → SMTP. The SMTP key is distinct from Brevo API keys. The login
and key must be URI encoded, for example @ becomes %40.
Use Brevo's Transactional Email API via the HTTP courier:
courier:
delivery_strategy: http
http:
request_config:
url: https://api.brevo.com/v3/smtp/email
method: POST
body: base64://<base64-encoded-jsonnet>
headers:
Content-Type: application/json
auth:
type: api_key
config:
name: api-key
value: <your-brevo-api-key>
in: header
The body is a Jsonnet template that turns the ctx object into a Brevo transactional email request. Set sender to
a sender verified in Brevo, then encode the template with Base64 as shown for SendGrid:
function(ctx) {
sender: {
email: '[email protected]',
name: 'Example',
},
to: [{ email: ctx.recipient }],
subject: ctx.subject,
textContent: ctx.body,
} + (
if std.objectHas(ctx, 'html_body') && ctx.html_body != ''
then { htmlContent: ctx.html_body }
else {}
)
To configure Brevo as your email provider, go to Authentication → Email Configuration in the Ory Console.
Mailchimp Transactional (Mandrill)
Mailchimp Transactional (formerly Mandrill) is a paid add-on to Mailchimp for transactional email — a natural choice when Mailchimp marketing is already in place.
Use the following connection URI:
smtps://apikey:<md-mandrill-api-key>@smtp.mandrillapp.com:465
The SMTP username can be any string (Mandrill ignores it but it must be present — apikey is conventional). The password is your
Mandrill API key from mandrillapp.com → Settings → SMTP & API Info.
Mailchimp Transactional is distinct from the Mailchimp marketing audience integration, which adds users to a Mailchimp list at registration via Ory Actions; see Mailchimp integration with Ory Actions.
SparkPost
SparkPost (a Bird/MessageBird company) is an enterprise-grade transactional email platform with per-region US / EU hosting.
- SMTP
- HTTP
Use the following connection URI. SparkPost uses STARTTLS on port 587:
# US
smtp://SMTP_Injection:<sparkpost-api-key>@smtp.sparkpostmail.com:587/
# EU
smtp://SMTP_Injection:<sparkpost-api-key>@smtp.eu.sparkpostmail.com:587/
The SMTP login is the literal string SMTP_Injection for all customers. The password is your SparkPost API key with the Send
via SMTP permission.
Use SparkPost's Transmissions API via the HTTP courier:
courier:
delivery_strategy: http
http:
request_config:
url: https://api.sparkpost.com/api/v1/transmissions # or api.eu.sparkpost.com
method: POST
body: base64://<base64-encoded-jsonnet>
headers:
Content-Type: application/json
auth:
type: api_key
config:
name: Authorization
value: <sparkpost-api-key>
in: header
The body is a Jsonnet template that turns the ctx object into a SparkPost transmission. Set from to a sending
domain verified in SparkPost, then encode the template with Base64 as shown for SendGrid:
function(ctx) {
recipients: [{ address: { email: ctx.recipient } }],
content: {
from: {
email: '[email protected]',
name: 'Example',
},
subject: ctx.subject,
text: ctx.body,
} + (
if std.objectHas(ctx, 'html_body') && ctx.html_body != ''
then { html: ctx.html_body }
else {}
),
}
SparkPost separates US and EU accounts — pick data residency before integration; account migrations are not trivial.
Your own server
- SMTP
- HTTP
You can send emails from your own SMTP server. Follow these steps to configure Ory to use a custom SMTP server:
- Ory Console
- Ory CLI
- Go to Authentication → Email Configuration in the Ory Console
- Toggle the Advanced Settings switch
- Add the configuration for your SMTP server
-
Download the Ory Kratos Identities config from your project and save it to a file:
## List all available workspacesory list workspaces## List all available projectsory list projects --workspace <workspace-id>## Get configory get identity-config --project <project-id> --workspace <workspace-id> --format yaml > identity-config.yaml -
Add the configuration for your custom SMTP server
identity-config.yamlcourier:delivery_strategy: smtpsmtp:connection_uri: smtp://username:password@server:port/from_address: [email protected]from_name: My Company
Note: The username and password must be URI encoded.
-
Update the Ory Kratos Identities configuration using the file you worked with:
ory update identity-config --project <project-id> --workspace <workspace-id> --file identity-config.yaml
SMTP security mechanisms
SMTP has six different security mechanisms. Most SMTP services today use Explicit StartTLS with trusted certificates.
-
Recommended: StartTLS with certificate trust verification. This is the most common option today:
smtp://username:password@server:port/ -
StartTLS without certificate trust verification:
smtp://username:password@server:port/?skip_ssl_verify=true -
Cleartext SMTP uses no encryption and is not secure. This option is often used in development environments:
smtp://username:password@server:port/?disable_starttls=true -
Implicit TLS with certificate trust verification:
smtps://username:password@server:port/ -
Implicit TLS without certificate trust verification:
smtps://username:password@server:port/?skip_ssl_verify=true -
Implicit TLS with certificate verification which works if the server is hosted on a subdomain and uses a non-wildcard domain certificate:
smtps://username:[email protected]:1234/?server_name=my-mailserver.com
Ory Kratos Identities supports sending emails using an HTTP server. This is useful if you want to customize the email content or use a service that doesn't provide an SMTP server.
- Ory Console
- Ory CLI
- Go to Authentication → Email Configuration in the Ory Console.
- Select HTTP Server.
- Configure your HTTP server.
- Click Save.
-
Download the Ory Kratos Identities config from your project and save it to a file:
## List all available workspacesory list workspaces## List all available projectsory list projects --workspace <workspace-id>## Get configory get identity-config --project <project-id> --workspace <workspace-id> --format yaml > identity-config.yaml -
Add the configuration for your custom HTTP server
identity-config.yamlcourier:delivery_strategy: httphttp:request_config:url: https://mail-sender.example.commethod: POSTbody: base64://... # See below for the default payload and available variablesheaders:Content-Type: application/jsonauth: # leave out, if your server doesn't require authentication, but note that we don't recommend thattype: basic_auth # or api_keyconfig:user: my-usernamepassword: my-password# if you want to use an API key (type: api_key), use the following config instead:# name: my-api-name# value: my-api-key-value# in: header # or cookie -
Update the Ory Kratos Identities configuration using the file you worked with:
ory update identity-config --project <project-id> --workspace <workspace-id> --file identity-config.yaml
The body is built from a Jsonnet template. See Payload for the ctx object the template receives and an example
template.
Payload
When you use the HTTP delivery strategy, Ory Kratos Identities sends each email as an HTTP request whose body is built from a
Jsonnet template. The template receives a ctx object that Ory Kratos Identities constructs for every message.
The ctx object
The ctx properties are defined by the httpDataModel struct in Ory Kratos.
// ...
type httpDataModel struct {
Recipient string `json:"recipient"`
Subject string `json:"subject"`
Body string `json:"body"`
// HTMLBody optionally contains the HTML version of an email template when available.
HTMLBody string `json:"html_body,omitempty"`
TemplateType template.TemplateType `json:"template_type"`
TemplateData Template `json:"template_data"`
MessageType string `json:"message_type"`
RequestHeaders json.RawMessage `json:"request_headers"`
}
// ...
The JSON tags on the struct are the field names available in ctx:
| Field | Type | Description |
|---|---|---|
recipient | String | The email address of the recipient. |
subject | String | The rendered email subject. |
body | String | The rendered plaintext body. |
html_body | String | The rendered HTML body, when available. |
template_type | String | The template type. See Events that trigger an email. |
template_data | Object | The per-template variables. See Available variables. |
message_type | String | The message channel, for example email. |
request_headers | Object | The HTTP headers from the flow request that triggered the email. |
Example Jsonnet template
The following is the mailer configuration template shipped with Ory Kratos. It maps the most common fields from ctx.
function(ctx) {
recipient: ctx.recipient,
template_type: ctx.template_type,
to: if "template_data" in ctx && "to" in ctx.template_data then ctx.template_data.to else null,
recovery_code: if "template_data" in ctx && "recovery_code" in ctx.template_data then ctx.template_data.recovery_code else null,
recovery_url: if "template_data" in ctx && "recovery_url" in ctx.template_data then ctx.template_data.recovery_url else null,
verification_url: if "template_data" in ctx && "verification_url" in ctx.template_data then ctx.template_data.verification_url else null,
verification_code: if "template_data" in ctx && "verification_code" in ctx.template_data then ctx.template_data.verification_code else null,
subject: if "template_data" in ctx && "subject" in ctx.template_data then ctx.template_data.subject else null,
body: if "template_data" in ctx && "body" in ctx.template_data then ctx.template_data.body else null,
html_body: if "template_data" in ctx && "html_body" in ctx.template_data then ctx.template_data.html_body else null
}
When using your own template, map top-level fields such as recipient and template_type directly from ctx. Map the other
fields your template needs from ctx.template_data.
Message-ID header
Ory Kratos Identities delivers every email at least once. If your SMTP server accepts an email but Ory Kratos Identities can't record the delivery, for example because the connection drops before the server confirms it, Ory Kratos Identities sends the email again.
Every email that Ory Kratos Identities sends over SMTP carries a Message-ID header that is the same on each delivery attempt:
Message-ID: <{message-id}@{sender-domain}>
{message-id}is the ID of the message, as listed in Activity → Message delivery in the Ory Console.{sender-domain}is the domain of the sender address,courier.smtp.from_address.
Mailbox providers and email clients use the Message-ID header to recognize copies of an email, and some, such as Gmail, show
only one copy. A resent email then usually doesn't reach the recipient's inbox twice. Some SMTP services replace the header with
their own value. Recipients of those services can receive a resent email twice.
Ory Kratos Identities always chooses the Message-ID header and ignores a Message-ID set in courier.smtp.headers. A
configured value would be the same for every email, and mailbox providers might treat different emails as copies of one email.
Troubleshooting
In general, if you have problems setting up email delivery, you can view outgoing messages on the Monitoring → Email Delivery page in the Ory Console.
The Sent state of an email only indicates whether Ory Kratos Identities successfully "handed" off the email to the SMTP server.
Emails do not arrive
The best way to figure out, why an email did not arrive is checking the Email Delivery dashboard in the Ory Console. It will show all emails sent by your project, along with its delivery state. If the Ory Network could not reach your SMTP server or there was an authentication failure, it will be indicated here along with the error message.
If the email's status is Sent, but it did not arrive, please check the spam folder or the logs of your custom SMTP server (if
configured).
Emails are marked as spam
If you're using a custom domain, but no custom SMTP server, some (or all) emails the Ory Network sends, can be marked as spam or blocked by the email providers of your users, such as Gmail. This is due to the phishing/spam protection these providers have in place to protect their users.
To read more, see Automated Emails but in short: we recommend setting up a custom SMTP server, if you use custom domains.