diff --git a/config/config.sample.php b/config/config.sample.php index 23e9cb5940afe..33b60b45eea75 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -519,7 +519,7 @@ 'mail_smtpdebug' => false, /** - * Which mode to use for sending mail: ``sendmail``, ``smtp`` or ``qmail``. + * Which mode to use for sending mail: ``sendmail``, ``smtp``, ``qmail`` or ``null``. * * If you are using local or remote SMTP, set this to ``smtp``. * @@ -529,6 +529,9 @@ * For ``qmail`` the binary is /var/qmail/bin/sendmail, and it must be installed * on your Unix system. * + * Use the ``null`` to send no mails (disable mail delivery). This can be useful + * if mails should be sent via APIs and rendering messages it not necessary. + * * Defaults to ``smtp`` */ 'mail_smtpmode' => 'smtp', diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index da3fcd3588871..c5124c5e31c7b 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -164,6 +164,11 @@ public function createEMailTemplate(string $emailId, array $data = []): IEMailTe * @return string[] $failedRecipients */ public function send(IMessage $message): array { + if ($this->config->getSystemValueString('mail_smtpmode', 'smtp') === 'null') { + // The null transport indicates no mail shall be sent + return []; + } + $debugMode = $this->config->getSystemValueBool('mail_smtpdebug', false); if (!($message instanceof Message)) { diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index f215e385e3f75..d6f410e775b8a 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -114,6 +114,19 @@ public function testGetSendmailInstanceSendMailQmail($sendmailMode, $binaryParam $this->assertEquals($sendmail, self::invokePrivate($this->mailer, 'getSendMailInstance')); } + public function testGetSendmailInstanceSendMailNull(): void { + $this->config + ->expects($this->exactly(1)) + ->method('getSystemValueString') + ->with('mail_smtpmode', 'smtp') + ->willReturn('null'); + + $this->dispatcher->expects($this->never()) + ->method('dispatchTyped'); + + $this->mailer->send($this->createMock(Message::class)); + } + public function testGetInstanceDefault(): void { $this->config ->method('getSystemValue')