Update mailer configurations for Symfony mailer

Newer Laravel uses Symfony mailer instead of SwiftMailer, and that means
that some configs and functionality have changed

In this change, we update config/mail.php with the new config layout and
name/functionality changes

of note:

* New configuration layout supporting lots of new/different mailers
* MAIL_DRIVER has become MAIL_MAILER, though we'll support both
* MAIL_ENCRYPTION is mostly useless, and we mark it as such -- symfony
  mailer detects which type of encryption to use automagically.
* MAIL_TLS_VERIFY_PEER is now available in case of self-signed
  certificates on the mail server, of if you want to access it by a
  different name, or by IP

Accordingly, we also update the .env examples, docker configs, and
the .env builder in the snipeit.sh installation script with the above
changes
This commit is contained in:
Jeremy Price 2024-02-28 23:37:52 -08:00
parent 8f2843bfcf
commit 8ace30ee23
12 changed files with 213 additions and 82 deletions

View file

@ -49,12 +49,12 @@ DB_SSL_CIPHER=null
# -------------------------------------------- # --------------------------------------------
# REQUIRED: OUTGOING MAIL SERVER SETTINGS # REQUIRED: OUTGOING MAIL SERVER SETTINGS
# -------------------------------------------- # --------------------------------------------
MAIL_DRIVER=smtp MAIL_MAILER=smtp
MAIL_HOST=mailhog MAIL_HOST=mailhog
MAIL_PORT=1025 MAIL_PORT=1025
MAIL_USERNAME=null MAIL_USERNAME=null
MAIL_PASSWORD=null MAIL_PASSWORD=null
MAIL_ENCRYPTION=null MAIL_TLS_VERIFY_PEER=true
MAIL_FROM_ADDR=you@example.com MAIL_FROM_ADDR=you@example.com
MAIL_FROM_NAME='Snipe-IT' MAIL_FROM_NAME='Snipe-IT'
MAIL_REPLYTO_ADDR=you@example.com MAIL_REPLYTO_ADDR=you@example.com

View file

@ -40,7 +40,7 @@ DB_SSL_CIPHER=null
# -------------------------------------------- # --------------------------------------------
# REQUIRED: OUTGOING MAIL SERVER SETTINGS # REQUIRED: OUTGOING MAIL SERVER SETTINGS
# -------------------------------------------- # --------------------------------------------
MAIL_DRIVER="log" MAIL_MAILER="log"
# -------------------------------------------- # --------------------------------------------

View file

@ -46,17 +46,21 @@ DB_SSL_CIPHER=null
# -------------------------------------------- # --------------------------------------------
# REQUIRED: OUTGOING MAIL SERVER SETTINGS # REQUIRED: OUTGOING MAIL SERVER SETTINGS
# -------------------------------------------- # --------------------------------------------
MAIL_DRIVER=smtp MAIL_MAILER=smtp
MAIL_HOST=email-smtp.us-west-2.amazonaws.com MAIL_HOST=email-smtp.us-west-2.amazonaws.com
MAIL_PORT=587 MAIL_PORT=587
MAIL_USERNAME=YOURUSERNAME MAIL_USERNAME=YOURUSERNAME
MAIL_PASSWORD=YOURPASSWORD MAIL_PASSWORD=YOURPASSWORD
MAIL_ENCRYPTION=null
MAIL_FROM_ADDR=you@example.com MAIL_FROM_ADDR=you@example.com
MAIL_FROM_NAME='Snipe-IT' MAIL_FROM_NAME='Snipe-IT'
MAIL_REPLYTO_ADDR=you@example.com MAIL_REPLYTO_ADDR=you@example.com
MAIL_REPLYTO_NAME='Snipe-IT' MAIL_REPLYTO_NAME='Snipe-IT'
MAIL_AUTO_EMBED_METHOD='attachment' MAIL_AUTO_EMBED_METHOD='attachment'
MAIL_TLS_VERIFY_PEER=true
# MAIL_ENCRYPTION is no longer supported. SymfonyMailer will use tls if it's
# advertised, and won't if it's not. If you want to use your mail server's IP but it's failing
# because of certificate errors, set MAIL_TLS_VERIFY_PEER-true
# -------------------------------------------- # --------------------------------------------
# REQUIRED: IMAGE LIBRARY # REQUIRED: IMAGE LIBRARY
@ -190,4 +194,4 @@ ARGON_TIME=2
# OPTIONAL: SCIM # OPTIONAL: SCIM
# -------------------------------------------- # --------------------------------------------
SCIM_TRACE=false SCIM_TRACE=false
SCIM_STANDARDS_COMPLIANCE=false SCIM_STANDARDS_COMPLIANCE=false

View file

@ -22,7 +22,7 @@ DB_PASSWORD=null
# -------------------------------------------- # --------------------------------------------
# REQUIRED: OUTGOING MAIL SERVER SETTINGS # REQUIRED: OUTGOING MAIL SERVER SETTINGS
# -------------------------------------------- # --------------------------------------------
MAIL_DRIVER=log MAIL_MAILER=log
# -------------------------------------------- # --------------------------------------------

View file

@ -18,6 +18,6 @@ APP_KEY=base64:tu9NRh/a6+dCXBDGvg0Gv/0TcABnFsbT4AKxrr8mwQo=
LOGIN_MAX_ATTEMPTS=1000000 LOGIN_MAX_ATTEMPTS=1000000
LOGIN_LOCKOUT_DURATION=100000000 LOGIN_LOCKOUT_DURATION=100000000
MAIL_DRIVER=log MAIL_MAILER=log
MAIL_FROM_ADDR=you@example.com MAIL_FROM_ADDR=you@example.com
MAIL_FROM_NAME=Snipe-IT MAIL_FROM_NAME=Snipe-IT

View file

@ -15,6 +15,6 @@ APP_KEY=base64:tu9NRh/a6+dCXBDGvg0Gv/0TcABnFsbT4AKxrr8mwQo=
LOGIN_MAX_ATTEMPTS=1000000 LOGIN_MAX_ATTEMPTS=1000000
LOGIN_LOCKOUT_DURATION=100000000 LOGIN_LOCKOUT_DURATION=100000000
MAIL_DRIVER=log MAIL_MAILER=log
MAIL_FROM_ADDR=you@example.com MAIL_FROM_ADDR=you@example.com
MAIL_FROM_NAME=Snipe-IT MAIL_FROM_NAME=Snipe-IT

View file

@ -38,7 +38,7 @@
"description": "The maximum number of search results that can be returned at one time.", "description": "The maximum number of search results that can be returned at one time.",
"value": "500" "value": "500"
}, },
"MAIL_DRIVER": { "MAIL_MAILER": {
"description": "Mail driver - Generally SMTP on Heroku - https://snipe-it.readme.io/docs/configuration#required-outgoing-mail-settings", "description": "Mail driver - Generally SMTP on Heroku - https://snipe-it.readme.io/docs/configuration#required-outgoing-mail-settings",
"value": "smtp" "value": "smtp"
}, },
@ -58,9 +58,9 @@
"description": "SMTP Server Password", "description": "SMTP Server Password",
"value": "YOURPASSWORD" "value": "YOURPASSWORD"
}, },
"MAIL_ENCRYPTION": { "MAIL_TLS_VERIFY_PEER": {
"description": "Encryption protocol for email sending.", "description": "Ensure validity of TLS certificate on remote mail server",
"value": "null" "value": true
}, },
"MAIL_FROM_ADDR": { "MAIL_FROM_ADDR": {
"description": "Email from address", "description": "Email from address",

View file

@ -6,10 +6,11 @@
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| This file reads from your .env configuration file and should not | This file reads from your .env configuration file and should not
| be modified directly. | be modified directly.
*/ */
return [ return [
/* /*
| *************************************************************************** | ***************************************************************************
| DO NOT MAKE CHANGES DIRECTLY TO THIS FILE. | DO NOT MAKE CHANGES DIRECTLY TO THIS FILE.
@ -30,33 +31,199 @@ return [
| |
*/ */
'driver' => env('MAIL_DRIVER', 'smtp'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| SMTP Host Address | Default Mailer
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| Here you may provide the host address of the SMTP server used by your | This option controls the default mailer that is used to send any email
| applications. A default option is provided that is compatible with | messages sent by your application. Alternative mailers may be setup
| the Mailgun mail service which will provide reliable deliveries. | and used as needed; however, this mailer will be used by default.
|
| Previous versions of Snipe-IT and Laravel used SwiftMailer, which used
| MAIL_DRIVER instead of MAIL_MAILER. In order to not break existing
| installations, we'll accept both
| |
*/ */
'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 'default' => env('MAIL_DRIVER') != null ? env('MAIL_DRIVER') : env('MAIL_MAILER', 'smtp'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| SMTP Host Port | Mailer Configurations
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| This is the SMTP port used by your application to deliver e-mails to | Here you may configure all of the mailers used by your application plus
| users of the application. Like the host we have set this value to | their respective settings. Several examples have been configured for
| stay compatible with the Mailgun e-mail application by default. | you and you are free to add your own as your application requires.
|
| Laravel supports a variety of mail "transport" drivers to be used while
| sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required.
|
| Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
| "postmark", "log", "array", "failover", "roundrobin"
| |
*/ */
'port' => env('MAIL_PORT', 587), 'mailers' => [
'smtp' => [
// Don't touch this. For the smtp mailer, the transport needs to be smtp
'transport' => 'smtp',
/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => env('MAIL_PORT', 587),
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => env('MAIL_USERNAME'),
/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/
'password' => env('MAIL_PASSWORD'),
/*
|--------------------------------------------------------------------------
| SMTP Server connection timeout
|--------------------------------------------------------------------------
|
| Give up trying to connect to the mail server after this many seconds
|
*/
'timeout' => 30,
/*
|--------------------------------------------------------------------------
| mostly pointless encryption option
|--------------------------------------------------------------------------
|
| This used to let you specify whether or not to use TLS, but now it really
| just helps inform the code about which SMTP port to use. SymfonMailer will
| still use TLS if the server offers it, regardless of how this is set.
| We're only including it here for reference, and the extreme edge-case where
| Symfony can't figure out what to do on its own.
|
*/
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
/*
|--------------------------------------------------------------------------
| Verify SMTP TLS certificate
|--------------------------------------------------------------------------
|
| As noted above, Swiftmailer WILL use TLS if the server offers it, so if
| you're using a self-signed certificate or want to refer to your mailserver
| by a name that isn't in the certificate (like the IP address), set this
| to 0 or false.
|
*/
'verify_peer' => env('MAIL_TLS_VERIFY_PEER', 1),
],
'ses' => [
'transport' => 'ses',
],
'postmark' => [
'transport' => 'postmark',
// 'message_stream_id' => null,
// 'client' => [
// 'timeout' => 5,
// ],
],
'mailgun' => [
'transport' => 'mailgun',
// 'client' => [
// 'timeout' => 5,
// ],
],
/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/
'sendmail' => [
'transport' => 'sendmail',
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
'failover' => [
'transport' => 'failover',
'mailers' => [
'smtp',
'log',
],
],
'roundrobin' => [
'transport' => 'roundrobin',
'mailers' => [
'ses',
'postmark',
],
],
],
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -70,9 +237,9 @@ return [
*/ */
'from' => [ 'from' => [
'address' => env('MAIL_FROM_ADDR', null), 'address' => env('MAIL_FROM_ADDR', null),
'name' => env('MAIL_FROM_NAME', null), 'name' => env('MAIL_FROM_NAME', null),
], ],
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -92,58 +259,18 @@ return [
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| E-Mail Encryption Protocol | Markdown Mail Settings
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| Here you may specify the encryption protocol that should be used when | If you are using Markdown based email rendering, you may configure your
| the application send e-mail messages. A sensible default using the | theme and component paths here, allowing you to customize the design
| transport layer security protocol should provide great security. | of the emails. Or, you may simply stick with the Laravel defaults!
| |
*/ */
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => env('MAIL_USERNAME'),
/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/
'password' => env('MAIL_PASSWORD'),
/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/
'sendmail' => env('SENDMAIL_PATH', ini_get('sendmail_path')),
'markdown' => [ 'markdown' => [
'theme' => 'default', 'theme' => 'default',
'paths' => [ 'paths' => [
resource_path('views/vendor/mail'), resource_path('views/vendor/mail'),
], ],

View file

@ -20,8 +20,8 @@ DB_DUMP_PATH='/usr/bin'
# -------------------------------------------- # --------------------------------------------
# REQUIRED: OUTGOING MAIL SERVER SETTINGS # REQUIRED: OUTGOING MAIL SERVER SETTINGS
# -------------------------------------------- # --------------------------------------------
MAIL_DRIVER=smtp MAIL_MAILER=smtp
MAIL_ENCRYPTION=${MAIL_ENV_ENCRYPTION} MAIL_TLS_VERIFY_PEER=${MAIL_TLS_VERIFY_PEER}
MAIL_FROM_ADDR=${MAIL_ENV_FROM_ADDR} MAIL_FROM_ADDR=${MAIL_ENV_FROM_ADDR}
MAIL_FROM_NAME=${MAIL_ENV_FROM_NAME} MAIL_FROM_NAME=${MAIL_ENV_FROM_NAME}
MAIL_REPLYTO_ADDR=${MAIL_ENV_FROM_ADDR} MAIL_REPLYTO_ADDR=${MAIL_ENV_FROM_ADDR}

View file

@ -25,12 +25,12 @@ DB_DUMP_PATH='/usr/bin'
# -------------------------------------------- # --------------------------------------------
# REQUIRED: OUTGOING MAIL SERVER SETTINGS # REQUIRED: OUTGOING MAIL SERVER SETTINGS
# -------------------------------------------- # --------------------------------------------
MAIL_DRIVER=smtp MAIL_MAILER=smtp
MAIL_HOST=${MAIL_PORT_587_TCP_ADDR} MAIL_HOST=${MAIL_PORT_587_TCP_ADDR}
MAIL_PORT=${MAIL_PORT_587_TCP_PORT} MAIL_PORT=${MAIL_PORT_587_TCP_PORT}
MAIL_USERNAME=${MAIL_ENV_USERNAME} MAIL_USERNAME=${MAIL_ENV_USERNAME}
MAIL_PASSWORD=${MAIL_ENV_PASSWORD} MAIL_PASSWORD=${MAIL_ENV_PASSWORD}
MAIL_ENCRYPTION=${MAIL_ENV_ENCRYPTION} MAIL_TLS_VERIFY_PEER=${MAIL_TLS_VERIFY_PEER}
MAIL_FROM_ADDR=${MAIL_ENV_FROM_ADDR} MAIL_FROM_ADDR=${MAIL_ENV_FROM_ADDR}
MAIL_FROM_NAME=${MAIL_ENV_FROM_NAME} MAIL_FROM_NAME=${MAIL_ENV_FROM_NAME}
MAIL_REPLYTO_ADDR=${MAIL_ENV_FROM_ADDR} MAIL_REPLYTO_ADDR=${MAIL_ENV_FROM_ADDR}

View file

@ -28,7 +28,7 @@
<env name="APP_ENV" value="testing"/> <env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/> <env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/> <env name="CACHE_DRIVER" value="array"/>
<env name="MAIL_DRIVER" value="array"/> <env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/> <env name="QUEUE_DRIVER" value="sync"/>
<env name="SESSION_DRIVER" value="array"/> <env name="SESSION_DRIVER" value="array"/>
<ini name="display_errors" value="true"/> <ini name="display_errors" value="true"/>

View file

@ -922,9 +922,9 @@ case $setupmail in
sed -i "s|^\\(MAIL_PASSWORD=\\).*|\\1$mailpassword|" "$APP_PATH/.env" sed -i "s|^\\(MAIL_PASSWORD=\\).*|\\1$mailpassword|" "$APP_PATH/.env"
echo "" echo ""
echo -n " Encryption(null/TLS/SSL):" echo -n " Verify TLS certificate on remote server? (true/false):"
read -r mailencryption read -r mailverifypeer
sed -i "s|^\\(MAIL_ENCRYPTION=\\).*|\\1$mailencryption|" "$APP_PATH/.env" sed -i "s|^\\(MAIL_TLS_VERIFY_PEER=\\).*|\\1$mailverifypeer|" "$APP_PATH/.env"
echo -n " From address:" echo -n " From address:"
read -r mailfromaddr read -r mailfromaddr