11---
22id : sending-emails-smtp
3- title : Use a custom server to send Ory Identity messages to users
4- sidebar_label : Email delivery configuration
3+ title : Email delivery configuration
54---
65
76``` mdx-code-block
@@ -10,21 +9,155 @@ import TabItem from "@theme/TabItem"
109import CodeBlock from "@theme/CodeBlock"
1110```
1211
13- The Ory Network comes with SMTP email sending configured out of the box . Ory emails are sent from this address:
12+ The Ory Network provides a default SMTP server for sending emails . Ory emails are sent from this address:
1413
1514```
1615{project.name} via Ory <[email protected] > 1716```
1817
1918:::info
2019
21- You must send emails using your SMTP server to change the sender address (` from_address ` ) and sender name (` from_name ` ).
20+ To customize the sender address, sender name, and email content, you need to use your own SMTP server. This prevents abuse and
21+ ensures high deliverability rates.
2222
2323:::
2424
25- ## Send emails using your SMTP server
25+ ## Integrations
2626
27- You can send emails from your own SMTP server. Follow these steps to configure Ory to use a custom SMTP server:
27+ Ory's email delivery system is flexible and can be configured to work with various email service providers. Below are the
28+ connection URIs and settings for some popular email service providers.
29+
30+ If a provider you use is not listed here, you can still configure Ory to use it by following the instructions in the
31+ [ Your own server] ( #your-own-server ) section.
32+
33+ :::info Need more flexibility?
34+
35+ Request an integration through our [ support channels] ( https://www.ory.sh/support ) or contribute one yourself by following the
36+ [ instructions on GitHub] ( https://github.com/ory/kratos ) .
37+
38+ :::
39+
40+ ### Sendgrid
41+
42+ <Tabs >
43+ <TabItem value = " smtp" label = " SMTP" >
44+
45+ Use the following connection URI and settings to
46+ [ send emails using Sendgrid] ( https://www.twilio.com/docs/sendgrid/for-developers/sending-email/integrating-with-the-smtp-api ) via
47+ SMTP.
48+
49+ - Sender address: an email address for a domain that has been verified in SendGrid via Domain Authentication (See your available
50+ [ senders] ( https://app.sendgrid.com/settings/sender_auth/senders ) .)
51+ - Port: ` 587 `
52+ - Security Mode: ` STARTTLS `
53+ - Username: ` apikey ` (constant string)
54+ - Hostname: ` smtp.sendgrid.net `
55+ - Password: the API key created in SendGrid, with the full “Mail Send” permission (no other permissions needed)
56+ - SMTP Headers: none
57+
58+ ```
59+ smtp://apikey:<YOUR_SENDGRID_API_KEY>@smtp.sendgrid.net:587/
60+
61+ # For example:
62+ smtp://apikey:[email protected] :587/ 63+ ```
64+
65+ </TabItem >
66+ <TabItem value = " http" label = " HTTP" >
67+
68+ Use the following connection URI and settings to
69+ [ send emails using Sendgrid] ( https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send ) via HTTP.
70+
71+ First, create a Sendgrid API key with the "Mail Send" permission on https://app.sendgrid.com/settings/api_keys .
72+
73+ Then, add the following configuration to your Ory Identities configuration:
74+
75+ ``` yaml title="kratos.yml"
76+ courier :
77+ delivery_strategy : http
78+ http :
79+ request_config :
80+ url : https://api.sendgrid.com/v3/mail/send
81+ method : POST
82+ body : file:///etc/config/kratos/mail.template.jsonnet
83+ headers :
84+ " Content-Type " : " application/json"
85+ auth :
86+ type : api_key
87+ config :
88+ name : Authorization
89+ value : Bearer <API_KEY>
90+ in : header
91+ ` ` `
92+
93+ Here is one example of a Jsonnet body:
94+
95+ ` ` ` jsonnet
96+ function(ctx) {
97+ " personalizations " : [
98+ {
99+ " to " : [
100+ {
101+ " email " : if "TemplateData" in ctx && "To" in ctx.TemplateData then ctx.TemplateData.To else null
102+ }
103+ ],
104+ " verificationCode " : if "TemplateData" in ctx && "VerificationCode" in ctx.TemplateData then ctx.TemplateData.VerificationCode else null
105+ }
106+ ],
107+ // Other values and personalizations .......
108+ }
109+ ```
110+
111+ </TabItem >
112+ </Tabs >
113+ To configure Sendgrid as your email provider, go to <ConsoleLink route = " project.emailConfiguration" />.
114+
115+ ### Mailgun
116+
117+ Use the following connection URI to
118+ [ send emails using Mailgun] ( https://documentation.mailgun.com/en/latest/quickstart-sending.html ) via SMTP.
119+
120+ Note: The username and password must be [ URI encoded] ( https://en.wikipedia.org/wiki/Percent-encoding ) .
121+
122+ ```
123+ smtp://{smtp-user}:{smtp-password}@smtp.mailgun.org:587
124+
125+ # For example:
126+ # smtp://some-user%40mailgun.example.org:[email protected] :587 127+ ```
128+
129+ ### AWS SES
130+
131+ Use the following connection URI to
132+ [ send emails using AWS SES SMTP] ( https://docs.aws.amazon.com/ses/latest/dg/send-email-smtp.html ) via SMTP.
133+
134+ Note: The username and password must be [ URI encoded] ( https://en.wikipedia.org/wiki/Percent-encoding ) .
135+
136+ ```
137+ smtp://{smtp-user}:{smtp-password}@email-smtp.{region}.amazonaws.com:587/
138+
139+ # For example:
140+ # smtp://theuser:[email protected] :587/ 141+ ```
142+
143+ ### Postmark
144+
145+ Use the following connection URI to [ send emails using Postmark] ( https://postmarkapp.com/smtp-service ) via SMTP.
146+
147+ Note: The username and password must be [ URI encoded] ( https://en.wikipedia.org/wiki/Percent-encoding ) .
148+
149+ ```
150+ smtp://{YOUR_POSTMARK_SEVER_API_TOKEN}:{YOUR_POSTMARK_SEVER_API_TOKEN}@smtp.postmarkapp.com:587/
151+
152+ # For example:
153+ # smtp://thetoken:[email protected] :587/ 154+ ```
155+
156+ ### Your own server
157+
158+ <Tabs >
159+ <TabItem value = " smtp" label = " SMTP" >
160+ You can send emails from your own SMTP server. Follow these steps to configure Ory to use a custom SMTP server:
28161
29162``` mdx-code-block
30163<Tabs groupId="console-or-cli">
@@ -77,104 +210,49 @@ Note: The username and password must be [URI encoded](https://en.wikipedia.org/w
77210</Tabs>
78211```
79212
80- ### SMTP security mechanisms
213+ #### SMTP security mechanisms
81214
82215SMTP has six different security mechanisms. Most SMTP services today use Explicit StartTLS with trusted certificates.
83216
842171 . ** Recommended** : StartTLS with certificate trust verification. This is the most common option today:
218+
85219 ```
86220 smtp://username:password@server:port/
87221 ```
222+
882232 . StartTLS without certificate trust verification:
224+
89225 ```
90226 smtp://username:password@server:port/?skip_ssl_verify=true
91227 ```
228+
922293 . Cleartext SMTP uses no encryption and is not secure. This option is often used in development environments:
230+
93231 ```
94232 smtp://username:password@server:port/?disable_starttls=true
95233 ```
234+
962354 . Implicit TLS with certificate trust verification:
236+
97237 ```
98238 smtps://username:password@server:port/
99239 ```
240+
1002415 . Implicit TLS without certificate trust verification:
242+
101243 ```
102244 smtps://username:password@server:port/?skip_ssl_verify=true
103245 ```
246+
1042476 . Implicit TLS with certificate verification which works if the server is hosted on a subdomain and uses a non-wildcard domain
105248 certificate:
249+
106250 ```
107251 smtps://username:[email protected] :1234/?server_name=my-mailserver.com 108252 ```
109253
110- ### SMTP Integrations
111-
112- Sample connection URIs to send emails via SMTP using different providers.
113-
114- #### Mailgun
115-
116- Use the following connection URI to
117- [ send emails using Mailgun] ( https://documentation.mailgun.com/en/latest/quickstart-sending.html ) via SMTP.
118-
119- Note: The username and password must be [ URI encoded] ( https://en.wikipedia.org/wiki/Percent-encoding ) .
120-
121- ```
122- smtp://{smtp-user}:{smtp-password}@smtp.mailgun.org:587
123-
124- # For example:
125- # smtp://some-user%40mailgun.example.org:[email protected] :587 126- ```
127-
128- #### AWS SES SMTP
129-
130- Use the following connection URI to
131- [ send emails using AWS SES SMTP] ( https://docs.aws.amazon.com/ses/latest/dg/send-email-smtp.html ) via SMTP.
132-
133- Note: The username and password must be [ URI encoded] ( https://en.wikipedia.org/wiki/Percent-encoding ) .
134-
135- ```
136- smtp://{smtp-user}:{smtp-password}@email-smtp.{region}.amazonaws.com:587/
137-
138- # For example:
139- # smtp://theuser:[email protected] :587/ 140- ```
141-
142- #### Postmark
143-
144- Use the following connection URI to [ send emails using Postmark] ( https://postmarkapp.com/smtp-service ) via SMTP.
145-
146- Note: The username and password must be [ URI encoded] ( https://en.wikipedia.org/wiki/Percent-encoding ) .
147-
148- ```
149- smtp://{YOUR_POSTMARK_SEVER_API_TOKEN}:{YOUR_POSTMARK_SEVER_API_TOKEN}@smtp.postmarkapp.com:587/
150-
151- # For example:
152- # smtp://thetoken:[email protected] :587/ 153- ```
154-
155- #### Sendgrid
156-
157- Use the following connection URI and settings to
158- [ send emails using Sendgrid] ( https://www.twilio.com/docs/sendgrid/for-developers/sending-email/integrating-with-the-smtp-api ) via
159- SMTP.
160-
161- - Sender address: an email address for a domain that has been verified in SendGrid via Domain Authentication
162- - Hostname: smtp.sendgrid.net
163- - Port: 587
164- - Security Mode: STARTTLS
165- - Username: apikey
166- - Password: the API key created in SendGrid, with the full “Mail Send” permission (no other permissions needed)
167- - SMTP Headers: none If you are unsure which port to use, a TLS connection on port 587 is typically recommended.
168-
169- ```
170- smtp://apikey:<YOUR_SENDGRID_API_KEY>@smtp.sendgrid.net:587/
171-
172- # For example:
173- smtp://apikey:[email protected] :587/ 174-
175- ```
176-
177- ## Send emails using an HTTP server
254+ </TabItem >
255+ <TabItem value = " http" label = " HTTP" >
178256
179257Ory Identities supports sending emails using an HTTP server. This is useful if you want to customize the email content or use a
180258service that doesn't provide an SMTP server.
@@ -272,52 +350,8 @@ The courier passes the following object as the `ctx` parameter into the Jsonnet
272350
273351In most cases, the default payload should be sufficient.
274352
275- ### HTTP Integrations
276-
277- Sample configurations to send emails via HTTP using different providers.
278-
279- #### Sendgrid
280-
281- Use the following connection URI and settings to
282- [ send emails using Sendgrid] ( https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send ) via HTTP.
283-
284- ```
285- ...
286- courier:
287- delivery_strategy: http
288- http:
289- request_config:
290- url: https://api.sendgrid.com/v3/mail/send
291- method: POST
292- body: file:///etc/config/kratos/mail.template.jsonnet
293- headers:
294- "Content-Type": "application/json"
295- auth:
296- type: api_key
297- config:
298- name: Authorization
299- value: Bearer <API_KEY>
300- in: header
301- ...
302- ```
303-
304- Here is one example of a Jsonnet body:
305-
306- ```
307- function(ctx) {
308- "personalizations": [
309- {
310- "to": [
311- {
312- "email": if "TemplateData" in ctx && "To" in ctx.TemplateData then ctx.TemplateData.To else null)
313- }
314- ],
315- "verificationCode": if "TemplateData" in ctx && "VerificationCode" in ctx.TemplateData then ctx.TemplateData.VerificationCode else null
316- }
317- ],
318- // Other values and personalizations .......
319- }
320- ```
353+ </TabItem >
354+ </Tabs >
321355
322356## Troubleshooting
323357
0 commit comments