Configure SMTP via separate environment variables
CI / Deploy / test (push) Successful in 1m2s
CI / Deploy / deploy (push) Skipped

Add SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD and SMTP_TLS instead of
requiring a transport URL, so passwords need no URL escaping. Port 465 uses
implicit SSL. EMAIL_TRANSPORT_DEFAULT_URL keeps working as a fallback.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-12 00:10:29 +01:00
1 parent 31df730374
commit df4445c1a4
5 files changed
+36 -20

No files matched your search

+6 -1
View File
@@ -17,7 +17,12 @@ APP_DEFAULT_LOCALE=de_DE
# --- Mail -------------------------------------------------------------------
# Empty = .eml files in tmp/mails/ (development only!)
# EMAIL_TRANSPORT_DEFAULT_URL=smtp://user:password@mail.example.org:587?tls=true
# SMTP_HOST=mail.example.org
# SMTP_PORT=587
# SMTP_USER=noreply@example.org
# SMTP_PASSWORD=secret
# true = STARTTLS (port 587); port 465 uses implicit SSL automatically; false = unencrypted
# SMTP_TLS=true
MAIL_FROM=noreply@plenario.example.org
MAIL_FROM_NAME=PlenarIO
+15 -10
View File
@@ -6,8 +6,15 @@ use Cake\Database\Connection;
use Cake\Database\Driver\Sqlite;
use Cake\Log\Engine\FileLog;
use Cake\Mailer\Transport\MailTransport;
use Cake\Mailer\Transport\SmtpTransport;
use function Cake\Core\env;
// SMTP from single variables (SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, SMTP_TLS) instead of a URL:
// no escaping of special characters in the password. Port 465 = implicit SSL, otherwise STARTTLS (SMTP_TLS).
$smtpHost = trim((string)env('SMTP_HOST', ''));
$smtpPort = (int)env('SMTP_PORT', 587);
$smtpSsl = $smtpPort === 465;
return [
/*
* PlenarIO application settings.
@@ -281,21 +288,19 @@ return [
*/
'EmailTransport' => [
'default' => [
'className' => MailTransport::class,
'className' => $smtpHost !== '' ? SmtpTransport::class : MailTransport::class,
/*
* The keys host, port, timeout, username, password, client and tls
* are used in SMTP transports
* are used in SMTP transports. Set them via SMTP_* environment variables.
*/
'host' => 'localhost',
'port' => 25,
'host' => $smtpHost !== '' ? ($smtpSsl ? 'ssl://' : '') . $smtpHost : 'localhost',
'port' => $smtpHost !== '' ? $smtpPort : 25,
'timeout' => 30,
/*
* It is recommended to set these options through your environment or app_local.php
*/
//'username' => null,
//'password' => null,
'username' => env('SMTP_USER') ?: null,
'password' => env('SMTP_PASSWORD') ?: null,
'client' => null,
'tls' => false,
'tls' => !$smtpSsl && filter_var(env('SMTP_TLS', true), FILTER_VALIDATE_BOOLEAN),
// Legacy alternative to the SMTP_* variables
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
+3 -4
View File
@@ -57,12 +57,11 @@ return [
'EmailTransport' => [
/*
* Local default: mails are written as .eml files to tmp/mails/.
* For production use SMTP, e.g.
* EMAIL_TRANSPORT_DEFAULT_URL=smtp://user:pass@mail.example.org:587?tls=true
* For real delivery set SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD and SMTP_TLS
* (see config/.env.example); then this override is skipped.
*/
'default' => [
'default' => env('SMTP_HOST') || env('EMAIL_TRANSPORT_DEFAULT_URL') ? [] : [
'className' => \App\Mailer\Transport\FileTransport::class,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
];