# certificate itself (Common Name or Subject Alternative Name).
MYSQL_ATTR_SSL_CA="/path/to/ca.pem"
-# Mail system to use
-# Can be 'smtp' or 'sendmail'
+# Mail configuration
+# Refer to https://www.bookstackapp.com/docs/admin/email-webhooks/#email-configuration
MAIL_DRIVER=smtp
-
-# Mail sending options
MAIL_FROM_NAME=BookStack
-# SMTP mail options
MAIL_HOST=localhost
-MAIL_PORT=1025
+MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_VERIFY_SSL=true
-# Command to use when email is sent via sendmail
MAIL_SENDMAIL_COMMAND="/usr/sbin/sendmail -bs"
# Cache & Session driver to use
* Do not edit this file unless you're happy to maintain any changes yourself.
*/
+// Configured mail encryption method.
+// STARTTLS should still be attempted, but tls/ssl forces TLS usage.
+$mailEncryption = env('MAIL_ENCRYPTION', null);
+
return [
// Mail driver to use.
'mailers' => [
'smtp' => [
'transport' => 'smtp',
+ 'scheme' => ($mailEncryption === 'tls' || $mailEncryption === 'ssl') ? 'smtps' : null,
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
- 'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'verify_peer' => env('MAIL_VERIFY_SSL', true),
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
+use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
use Tests\TestCase;
/**
});
}
+ public function test_non_null_mail_encryption_options_enforce_smtp_scheme()
+ {
+ $this->checkEnvConfigResult('MAIL_ENCRYPTION', 'tls', 'mail.mailers.smtp.scheme', 'smtps');
+ $this->checkEnvConfigResult('MAIL_ENCRYPTION', 'ssl', 'mail.mailers.smtp.scheme', 'smtps');
+ $this->checkEnvConfigResult('MAIL_ENCRYPTION', 'null', 'mail.mailers.smtp.scheme', null);
+ }
+
+ public function test_smtp_scheme_and_certain_port_forces_tls_usage()
+ {
+ $isMailTlsForcedEnabled = function () {
+ $transport = Mail::mailer('smtp')->getSymfonyTransport();
+ /** @var SocketStream $stream */
+ $stream = $transport->getStream();
+ Mail::purge('smtp');
+ return $stream->isTLS();
+ };
+
+ config()->set([
+ 'mail.mailers.smtp.scheme' => null,
+ 'mail.mailers.smtp.port' => 587,
+ ]);
+
+ $this->assertFalse($isMailTlsForcedEnabled());
+
+ config()->set([
+ 'mail.mailers.smtp.scheme' => 'smtps',
+ 'mail.mailers.smtp.port' => 587,
+ ]);
+
+ $this->assertTrue($isMailTlsForcedEnabled());
+
+ config()->set([
+ 'mail.mailers.smtp.scheme' => '',
+ 'mail.mailers.smtp.port' => 465,
+ ]);
+
+ $this->assertTrue($isMailTlsForcedEnabled());
+ }
+
/**
* Set an environment variable of the given name and value
* then check the given config key to see if it matches the given result.