diff --git a/config/config.sample.php b/config/config.sample.php index 7a86070c18..299e67c98f 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -421,6 +421,13 @@ $CONFIG = array( */ '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 7a8b4ad259..2dad72b5b1 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -259,6 +259,10 @@ class Mailer implements IMailer { if (!empty($smtpSecurity)) { $transport->setEncryption($smtpSecurity); } + $streamingOptions = $this->config->getSystemValue('mail_smtpstreamoptions', array()); + if (is_array($streamingOptions) && count($streamingOptions) > 0) { + $transport->setStreamOptions($streamingOptions); + } return $transport; } diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index 4117498885..8c309335ab 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -167,4 +167,26 @@ class MailerTest extends TestCase { $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'])); + + } + + public function testStreamingOptionsWrongType() { + $this->config->method('getSystemValue') + ->will($this->returnValueMap([ + ['mail_smtpmode', 'smtp', 'smtp'], + ['mail_smtpstreamoptions', array(), 'bar'] + ])); + $mailer = self::invokePrivate($this->mailer, 'getInstance'); + $this->assertEquals(0, count($mailer->getTransport()->getStreamOptions())); + } }