Debian Codegraph @

docs/services/email/smtp/index.md

raw
1 # Email
2
3 Shoutrrr can send notifications as email over SMTP.
4 It talks to any RFC 5321 server (Gmail, Microsoft 365, self-hosted Postfix, and similar) using a single service URL.
5
6 ## URL Format
7
8 !!! info ""
9 smtp://__`username`__:__`password`__@__`host`__:__`port`__/?fromaddress=__`fromAddress`__&toaddresses=__`recipient1`__[,__`recipient2`__,...]&subject=__`subject`__&auth=__`auth`__&encryption=__`encryption`__&useStartTLS=__`yes/no`__&useHTML=__`yes/no`__&clientHost=__`hostname`__&requirestarttls=__`yes/no`__&skiptlsverify=__`yes/no`__&timeout=__`duration`__
10
11 --8<-- "docs/services/email/smtp/config.md"
12
13 ## Getting Started
14
15 Every SMTP URL needs a `host`, a `fromaddress`, and at least one `toaddresses` recipient.
16
17 A `Username` and `Password` are required only when the server expects authentication.
18
19 !!! Example "Minimal authenticated send"
20
21 ```uri
22 smtp://user:[email protected]:587/[email protected]&[email protected]&requirestarttls=yes
23 ```
24
25 Connects to `mail.example.com` on port 587, authenticates as `user`, and sends to `[email protected]`.
26
27 ## Configuration Parameters
28
29 ### Host and Port
30
31 - `Host` is the SMTP server hostname or IP address and is required.
32 - `Port` defaults to `25`.
33
34 Common ports:
35
36 - __25__: traditional SMTP (often blocked on residential networks)
37 - __587__: submission with STARTTLS
38 - __465__: implicit TLS (SMTPS)
39 - __2525__: alternate submission port used by some providers
40
41 !!! Example "Submission on 587"
42
43 ```uri
44 smtp://user:[email protected]:587/[email protected]&[email protected]&requirestarttls=yes
45 ```
46
47 ### Username and Password
48
49 - `Username` and `Password` are the SMTP credentials.
50 - Both default to empty.
51 - Leave them empty for servers that allow unauthenticated relay.
52 - For `auth=OAuth2`, put the access token in the password field.
53
54 !!! Example "No credentials"
55
56 ```uri
57 smtp://mail.example.com:25/[email protected]&[email protected]&auth=None
58 ```
59
60 ### From Address and From Name
61
62 - `fromaddress` (alias `from`) is the envelope and header From address and is required.
63 - `fromname` is an optional display name shown by mail clients.
64
65 !!! Example "Named sender"
66
67 ```uri
68 smtp://user:[email protected]:587/[email protected]&fromname=Shoutrrr&[email protected]&requirestarttls=yes
69 ```
70
71 ### Recipients
72
73 - `toaddresses` (alias `to`) is a comma-separated list of recipient addresses and is required.
74 - Plus-tags in addresses (`[email protected]`) are preserved and spaces that come from URL-decoding `+` are turned back into `+`.
75
76 !!! Example "Multiple recipients"
77
78 ```uri
79 smtp://user:[email protected]:587/[email protected]&[email protected],[email protected]&requirestarttls=yes
80 ```
81
82 !!! Example "Plus-address recipient"
83
84 ```uri
85 smtp://user:[email protected]:587/[email protected]&[email protected]&requirestarttls=yes
86 ```
87
88 ### Subject
89
90 - `subject` (alias `title`) is the email subject.
91 - When the URL omits `subject`, the header is empty.
92
93 !!! Example "Custom subject"
94
95 ```uri
96 smtp://user:[email protected]:587/[email protected]&[email protected]&subject=Disk%20space%20low&requirestarttls=yes
97 ```
98
99 ### Authentication
100
101 `auth` selects the SMTP AUTH method. Default: `Unknown`.
102
103 | Value | Behavior |
104 |-----------|--------------------------------------------------------------------------------|
105 | `None` | No AUTH |
106 | `Plain` | AUTH PLAIN (username and password) |
107 | `Login` | AUTH LOGIN, for servers that do not support PLAIN |
108 | `CRAMMD5` | AUTH CRAM-MD5 |
109 | `OAuth2` | SASL XOAUTH2 with a __static__ access token in the password field (no refresh) |
110 | `Unknown` | If a username is set, treated as `Plain`; otherwise `None` |
111
112 `Plain`, `Login`, and `OAuth2` refuse to send credentials on an unencrypted connection unless the server name is `localhost`, `127.0.0.1`, or `::1`.
113
114 !!! Example "AUTH LOGIN"
115
116 ```uri
117 smtp://user:[email protected]:587/[email protected]&[email protected]&auth=Login&requirestarttls=yes
118 ```
119
120 !!! Example "OAuth2 access token"
121
122 ```uri
123 smtp://user:[email protected]:587/[email protected]&[email protected]&auth=OAuth2&requirestarttls=yes
124 ```
125
126 The token is not refreshed.
127 Supply a current access token for each send.
128
129 ### Encryption
130
131 - `encryption` selects how TLS is applied. Default: `Auto`.
132 - `usestarttls` defaults to yes and is independent of `encryption`.
133 - `encryption=None` still attempts STARTTLS unless you also set `usestarttls=no`.
134
135 | Value | Behavior |
136 |---------------|------------------------------------------------------------------------------------------------------|
137 | `None` | No implicit TLS; STARTTLS is still attempted unless `usestarttls=no` |
138 | `ExplicitTLS` | STARTTLS after connect when `usestarttls` is enabled; with `usestarttls=no` the session is plaintext |
139 | `ImplicitTLS` | TLS from the first byte (typical for port 465) |
140 | `Auto` | Implicit TLS on port 465; otherwise STARTTLS when `usestarttls` is enabled |
141
142 !!! Example "Implicit TLS on 465"
143
144 ```uri
145 smtp://user:[email protected]:465/[email protected]&[email protected]&encryption=ImplicitTLS
146 ```
147
148 ### StartTLS
149
150 - `usestarttls` (alias `starttls`) defaults to yes.
151 - When enabled and the server does not advertise STARTTLS, Shoutrrr logs a warning and continues unencrypted unless `requirestarttls` is set.
152
153 !!! Example "Disable STARTTLS"
154
155 ```uri
156 smtp://user:[email protected]:25/[email protected]&[email protected]&usestarttls=no
157 ```
158
159 ### Require StartTLS
160
161 - `requirestarttls` defaults to no.
162 - When yes, send fails if STARTTLS is enabled but the server does not support it.
163
164 !!! Example "Fail closed without STARTTLS"
165
166 ```uri
167 smtp://user:[email protected]:587/[email protected]&[email protected]&requirestarttls=yes
168 ```
169
170 ### Skip TLS Certificate Verification
171
172 - `skiptlsverify` defaults to no.
173 - When TLS is negotiated, `yes` disables server certificate verification; however, it does not enable TLS.
174
175 !!! danger "Security Risk"
176 Skipping certificate verification makes the connection vulnerable to man-in-the-middle attacks.
177 Only use this on networks you trust, such as a lab or an internal mail relay with a private CA.
178
179 !!! Example "Skip verify on an internal relay"
180
181 ```uri
182 smtp://user:[email protected]:587/[email protected]&[email protected]&skiptlsverify=yes&requirestarttls=yes
183 ```
184
185 ### HTML Body
186
187 - `usehtml` defaults to no.
188 - When yes, the message is sent as `multipart/alternative` with a `text/plain` part and a `text/html` part.
189 - The same message string is used for both parts.
190 - The HTML part is sent __as-is__.
191
192 !!! Example "HTML notification"
193
194 ```uri
195 smtp://user:[email protected]:587/[email protected]&[email protected]&usehtml=yes&requirestarttls=yes
196 ```
197
198 Pass HTML as the message body, for example `<p>Disk usage is <strong>92%</strong>.</p>`.
199
200 ### Client Host
201
202 - `clienthost` is the hostname sent in the SMTP `EHLO`/`HELO` handshake.
203 - Default: `localhost`.
204 - Set it to `auto` to use the operating system hostname (falling back to `localhost` if lookup fails).
205
206 !!! Example "Auto client host"
207
208 ```uri
209 smtp://user:[email protected]:587/[email protected]&[email protected]&clienthost=auto&requirestarttls=yes
210 ```
211
212 ### Timeout
213
214 - `timeout` is a Go duration covering the TCP/TLS dial and the SMTP session (EHLO, AUTH, DATA, QUIT).
215 - Default: `10s`.
216 - With no sender timeout set, the router waits this long for SMTP, including values above 10s. A positive `SenderOptions.Timeout` is the exact fixed timeout for every service on that sender.
217
218 !!! Example "Thirty-second timeout"
219
220 ```uri
221 smtp://user:[email protected]:587/[email protected]&[email protected]&timeout=30s&requirestarttls=yes
222 ```
223
224 ## Message Templates
225
226 - SMTP templates are only available via the __Shoutrrr API__.
227 - They are not URL or CLI parameters.
228 - IDs are `"plain"` and `"HTML"`.
229 - The template data map has a `message` key.
230
231 !!! Example "`<div>`-wrapped message body"
232
233 ```go
234 err := service.SetTemplateString("HTML", `<div>{{ .message }}</div>`)
235 ```
236
237 !!! Example "If you want a `<pre>` wrapper around an HTML part, include it in the message or set an `"HTML"` template"
238
239 ```go
240 err := service.SetTemplateString("HTML", `<pre>{{ .message }}</pre>`)
241 ```
242
243 ## Examples
244
245 !!! Example "STARTTLS on port 587"
246
247 ```uri
248 smtp://user:[email protected]:587/[email protected]&[email protected]&requirestarttls=yes
249 ```
250
251 !!! Example "Implicit TLS on port 465"
252
253 ```uri
254 smtp://user:[email protected]:465/[email protected]&[email protected]&encryption=ImplicitTLS
255 ```
256
257 !!! Example "HTML body"
258
259 ```uri
260 smtp://user:[email protected]:587/[email protected]&[email protected]&usehtml=yes&subject=Alert&requirestarttls=yes
261 ```
262
263 !!! Example "Plus-address recipient"
264
265 ```uri
266 smtp://user:[email protected]:587/[email protected]&[email protected]&requirestarttls=yes
267 ```
268
269 !!! Example "Unauthenticated local relay"
270
271 ```uri
272 smtp://127.0.0.1:25/[email protected]&[email protected]&auth=None&usestarttls=no
273 ```