Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "null" STMP transport mode #48977

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
*
Expand All @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions lib/private/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/Mail/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down