You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: configuration.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,9 +41,11 @@ Here are the available configuration options and their default values:
41
41
|`environment`| development | The environment in which SQLPage is running. Can be either `development` or `production`. In `production` mode, SQLPage will hide error messages and stack traces from the user, and will cache sql files in memory to avoid reloading them from disk. |
42
42
|`cache_stale_duration_ms`| 1000 (prod), 0 (dev) | The duration in milliseconds that a file can be cached before its freshness is checked against the filesystem. Defaults to 1000ms (1 second) in production and 0ms in development. |
43
43
|`content_security_policy`|`script-src 'self' 'nonce-{NONCE}'`| The [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) to set in the HTTP headers. If you get CSP errors in the browser console, you can set this to the empty string to disable CSP. If you want a custom CSP that contains a nonce, include the `'nonce-{NONCE}'` directive in your configuration string and it will be populated with a random value per request. |
44
-
|`smtp_host`|| SMTP server used by the `sqlpage.send_mail` function. Accepts only a host name or `host:port`; if no port is provided, SQLPage uses port 25. Set with `SMTP_HOST` in the environment. |
44
+
|`smtp_host`|| SMTP server host used by the `sqlpage.send_mail` function. Set with `SMTP_HOST` in the environment. |
45
+
|`smtp_port`| 25 (`none`), 465 (`tls`), or 587 (`starttls`) | SMTP server port. The default depends on `smtp_tls_mode`. Set this explicitly for relays using a nonstandard port. |
45
46
|`smtp_username`|| Optional SMTP user name for `sqlpage.send_mail`. When set, SQLPage authenticates to `SMTP_HOST` using this user name and `smtp_password`. Credentials require `smtp_tls_mode` to be `starttls` or `tls`. |
46
-
|`smtp_password`|| Optional SMTP password for `sqlpage.send_mail` when `smtp_username` is set. |
47
+
|`smtp_password`|| Optional SMTP password for `sqlpage.send_mail`. `smtp_username` and `smtp_password` must be configured together. |
48
+
|`smtp_from`|| Default sender address for `sqlpage.send_mail`, optionally including a display name. Individual messages can override it with their `from` property. |
47
49
|`smtp_tls_mode`|`starttls`| Encryption mode for `sqlpage.send_mail`: `starttls` requires a STARTTLS upgrade, `tls` uses TLS from connection start, and `none` permits plaintext only without credentials for trusted local SMTP servers. |
48
50
|`system_root_ca_certificates`| false | Whether to use the system root CA certificates to validate SSL certificates when making http requests with `sqlpage.fetch`. If set to false, SQLPage will use its own set of root CA certificates. If the `SSL_CERT_FILE` or `SSL_CERT_DIR` environment variables are set, they will be used instead of the system root CA certificates. |
49
51
|`max_recursion_depth`| 10 | Maximum depth of recursion allowed in the `run_sql` function. Maximum value is 255. |
Copy file name to clipboardExpand all lines: examples/official-site/sqlpage/migrations/75_send_mail.sql
+10-12Lines changed: 10 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -2,40 +2,39 @@ INSERT INTO sqlpage_functions (
2
2
"name",
3
3
"introduced_in_version",
4
4
"icon",
5
-
"description_md",
6
-
"return_type"
5
+
"description_md"
7
6
)
8
7
VALUES (
9
8
'send_mail',
10
9
'0.45.0',
11
10
'mail',
12
11
'Sends an email using the SMTP server configured with `SMTP_HOST`.
13
12
14
-
`SMTP_HOST` must contain only a host name or `host:port`; URL schemes and paths are rejected. When no port is specified, SQLPage uses port 25.
13
+
`SMTP_HOST` contains the relay host name. Set `SMTP_PORT` when the relay does not use the default for the selected encryption mode: 587 for `starttls`, 465 for `tls`, or 25 for `none`.
15
14
16
15
`SMTP_TLS_MODE` defaults to `starttls`, which requires a STARTTLS upgrade before sending email or credentials. Set it to `tls` for implicit TLS, commonly used on port 465. Plaintext mode (`none`) is allowed only without credentials and should be used only for trusted local SMTP servers.
17
16
18
17
If your SMTP server requires authentication, configure `SMTP_USERNAME` and `SMTP_PASSWORD` as well.
19
18
20
19
The function accepts a single JSON object argument. The required properties are:
21
20
22
-
- `recipient`: email address to send to, optionally including a display name such as `"Jane Doe <jane@example.com>"`.
21
+
- `to`: email address to send to, optionally including a display name such as `"Jane Doe <jane@example.com>"`.
23
22
- `subject`: email subject.
24
23
- `body`: plain text email body.
25
24
26
25
Optional properties:
27
26
28
-
- `sender`: sender address. Defaults to `SQLPage <sqlpage@localhost>`.
27
+
- `from`: sender address. It may be omitted when `SMTP_FROM` configures a default sender.
29
28
- `reply_to`: reply-to address.
30
29
31
-
After the SMTP server accepts the message, the function returns its JSON argument unchanged. It returns `NULL` when passed `NULL`, and raises an error if the message cannot be sent.
30
+
The function returns `NULL` after the SMTP relay accepts the message and raises an error if the message cannot be sent. The argument is required; passing `NULL` is an error.
32
31
33
32
### Example
34
33
35
34
```sql
36
35
set message = json_object(
37
-
''recipient'', ''admin@example.com'',
38
-
''sender'', ''contact@example.com'',
36
+
''to'', ''admin@example.com'',
37
+
''from'', ''contact@example.com'',
39
38
''subject'', ''New contact form message'',
40
39
''body'', ''Hello from SQLPage!''
41
40
);
@@ -50,16 +49,15 @@ select ''email'' as name, ''email'' as type, true as required;
50
49
select ''message'' as name, ''textarea'' as type, true as required;
51
50
52
51
set mail = json_object(
53
-
''recipient'', ''admin@example.com'',
52
+
''to'', ''admin@example.com'',
54
53
''reply_to'', $email,
55
54
''subject'', ''Website contact form'',
56
55
''body'', $message
57
56
);
58
57
select sqlpage.send_mail($mail)
59
58
where $message is not null;
60
59
```
61
-
',
62
-
'JSON'
60
+
'
63
61
);
64
62
65
63
INSERT INTO sqlpage_function_parameters (
@@ -73,6 +71,6 @@ VALUES (
73
71
'send_mail',
74
72
1,
75
73
'message',
76
-
'A JSON object containing the email to send. Required properties are `recipient`, `subject`, and `body`. Optional properties are `sender` and `reply_to`.',
74
+
'A JSON object containing the email to send. Required properties are `to`, `subject`, and `body`. Optional properties are `from` (required unless `SMTP_FROM` is configured) and `reply_to`. Unknown properties are rejected to catch misspellings.',
Copy file name to clipboardExpand all lines: examples/sending emails/README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,22 +10,22 @@ docker compose up
10
10
11
11
Open http://localhost:8080 to send an email, then inspect it in the Mailpit inbox at http://localhost:8025.
12
12
13
-
The SMTP server is configured in [`docker-compose.yml`](./docker-compose.yml) with `SMTP_HOST=mailpit:1025` and `SMTP_TLS_MODE=none`. Plaintext mode is intended only for trusted local SMTP servers such as Mailpit.
13
+
The SMTP server is configured in [`docker-compose.yml`](./docker-compose.yml) with `SMTP_HOST=mailpit`, `SMTP_PORT=1025`, and `SMTP_TLS_MODE=none`. Plaintext mode is intended only for trusted local SMTP servers such as Mailpit.
14
14
15
15
For a remote SMTP relay, keep the default `SMTP_TLS_MODE=starttls`, or set it to `tls` when the relay requires implicit TLS. Configure `SMTP_USERNAME` and `SMTP_PASSWORD` when authentication is required; SQLPage rejects credentials in plaintext mode.
16
16
17
17
The form handler sends the message with a single function call:
18
18
19
19
```sql
20
20
set message = json_object(
21
-
'recipient', :recipient,
22
-
'sender', :sender,
21
+
'to', :recipient,
22
+
'from', :sender,
23
23
'subject', :subject,
24
24
'body', :body
25
25
);
26
-
setsent_message=sqlpage.send_mail($message);
26
+
set_=sqlpage.send_mail($message);
27
27
```
28
28
29
-
After the SMTP server accepts the email, `sqlpage.send_mail` returns the message JSON unchanged. It raises an error when delivery to the SMTP server fails.
29
+
`sqlpage.send_mail` returns `NULL` after the SMTP relay accepts the message. It raises an error when the relay rejects the message or cannot be reached, so statements after the call run only on success.
30
30
31
31
Do not expose an unrestricted form like this publicly. In production, authenticate users, restrict recipients, validate input, and add rate limiting to prevent abuse.
0 commit comments