diff --git a/config/config.sample.php b/config/config.sample.php index 7a86070c18fe8..299e67c98fe23 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -421,6 +421,13 @@ */ 'mail_send_plaintext_only' => false, +/** + * This depends on ``mail_smtpmode``. Array of additional streams options that + * will be passed to underlying Swift mailer implementation. + * Defaults to an empty array. + */ +'mail_smtpstreamoptions' => array(), + /** * Which mode is used for sendmail/qmail: ``smtp`` or ``pipe``. * diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 7a8b4ad2599f3..b9f97bd9d95c1 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -259,6 +259,10 @@ protected function getSmtpInstance(): \Swift_SmtpTransport { if (!empty($smtpSecurity)) { $transport->setEncryption($smtpSecurity); } + $streamingOptions = $this->config->getSystemValue('mail_smtpstreamoptions', array()); + if (count($streamingOptions) > 0) { + $transport->setStreamOptions($streamingOptions); + } return $transport; } diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index 4117498885c35..97df9784f6ca8 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -167,4 +167,15 @@ public function testCreateEMailTemplate() { $this->assertSame(EMailTemplate::class, get_class($this->mailer->createEMailTemplate('tests.MailerTest'))); } + + public function testStreamingOptions() { + $this->config->method('getSystemValue') + ->will($this->returnValueMap([ + ['mail_smtpmode', 'smtp', 'smtp'], + ['mail_smtpstreamoptions', array(), array('foo' => 1)] + ])); + $mailer = self::invokePrivate($this->mailer, 'getInstance'); + $this->assertEquals(1, count($mailer->getTransport()->getStreamOptions())); + $this->assertTrue(isset($mailer->getTransport()->getStreamOptions()['foo'])); + } }