-
-
Notifications
You must be signed in to change notification settings - Fork 175
Add SMTP send_mail SQL function with configuration and lettre integration
#1346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
72e695e
77797c9
9659fed
00b969f
214a986
1839738
93afed9
e8e590d
e71fe45
71d0837
889277f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| INSERT INTO sqlpage_functions ( | ||
| "name", | ||
| "introduced_in_version", | ||
| "icon", | ||
| "description_md", | ||
| "return_type" | ||
| ) | ||
| VALUES ( | ||
| 'send_mail', | ||
| '0.45.0', | ||
| 'mail', | ||
| 'Sends an email using the SMTP server configured with `SMTP_HOST`. | ||
|
|
||
| `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. | ||
|
|
||
| `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. | ||
|
|
||
| If your SMTP server requires authentication, configure `SMTP_USERNAME` and `SMTP_PASSWORD` as well. | ||
|
|
||
| The function accepts a single JSON object argument. The required properties are: | ||
|
|
||
| - `recipient`: email address to send to, optionally including a display name such as `"Jane Doe <jane@example.com>"`. | ||
| - `subject`: email subject. | ||
| - `body`: plain text email body. | ||
|
|
||
| Optional properties: | ||
|
|
||
| - `sender`: sender address. Defaults to `SQLPage <sqlpage@localhost>`. | ||
| - `reply_to`: reply-to address. | ||
|
|
||
| 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. | ||
|
|
||
| ### Example | ||
|
|
||
| ```sql | ||
| set message = json_object( | ||
| ''recipient'', ''admin@example.com'', | ||
| ''sender'', ''contact@example.com'', | ||
| ''subject'', ''New contact form message'', | ||
| ''body'', ''Hello from SQLPage!'' | ||
| ); | ||
| select sqlpage.send_mail($message); | ||
| ``` | ||
|
|
||
| ### Contact form example | ||
|
|
||
| ```sql | ||
| select ''form'' as component, ''post'' as method; | ||
| select ''email'' as name, ''email'' as type, true as required; | ||
| select ''message'' as name, ''textarea'' as type, true as required; | ||
|
|
||
| set mail = json_object( | ||
| ''recipient'', ''admin@example.com'', | ||
| ''reply_to'', $email, | ||
| ''subject'', ''Website contact form'', | ||
| ''body'', $message | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For this POST form, the submitted fields need to be read with Useful? React with 👍 / 👎. |
||
| ); | ||
| select sqlpage.send_mail($mail) | ||
| where $message is not null; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In this contact-form example, the unaliased Useful? React with 👍 / 👎. |
||
| ``` | ||
| ', | ||
| 'JSON' | ||
| ); | ||
|
|
||
| INSERT INTO sqlpage_function_parameters ( | ||
| "function", | ||
| "index", | ||
| "name", | ||
| "description_md", | ||
| "type" | ||
| ) | ||
| VALUES ( | ||
| 'send_mail', | ||
| 1, | ||
| 'message', | ||
| 'A JSON object containing the email to send. Required properties are `recipient`, `subject`, and `body`. Optional properties are `sender` and `reply_to`.', | ||
| 'JSON' | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Docker build path I checked,
scripts/setup-cross-compilation.shonly installs/stagesgcc,libgccandmake, and theDockerfileonly copies/tmp/sqlpage-libs/*into the busybox runtime image. Enabling lettre'stokio1-native-tlsfeature here pullsnative-tls/openssl-sys, so the Linux Docker builds now need OpenSSL headers/pkg-config at build time and libssl/libcrypto plus trust roots at runtime; without adding those for each target, the published minimal/duckdb images can fail to build or start. Prefer lettre's rustls backend or add the OpenSSL build/runtime dependencies explicitly.Useful? React with 👍 / 👎.