Skip to content

Commit

Permalink
IONOS(feat): add "null" STMP transport mode
Browse files Browse the repository at this point in the history
This is an cherry-picked, early commit of the still pending PR nextcloud#48977.

== Goal

Allow disabling mail delivery altogether.

== Usecase

If mails ought to be send by other means than rendering messages from
templates and sending them via SMTP-like protocols.

Example: listening to specific Nextcloud events and pass parameters to
a centralized (i.e. REST-based) API that sends e-mails.

Signed-off-by: Thomas Lehmann <[email protected]>
  • Loading branch information
thlehmann-ionos committed Oct 29, 2024
1 parent a02c486 commit fcccc0f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,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 @@ -511,6 +511,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 @@ -113,6 +113,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() {
$this->config
->method('getSystemValue')
Expand Down

0 comments on commit fcccc0f

Please sign in to comment.