Skip to content

Commit

Permalink
fix: Mailer::send will always thrown an exception in case of errors d…
Browse files Browse the repository at this point in the history
…uring delivery
  • Loading branch information
DeepDiver1975 committed Oct 6, 2023
1 parent 4d7271e commit b7c4f0c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
5 changes: 0 additions & 5 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,7 @@ public function schedule(ITip\Message $iTipMessage) {
->setSubject($subject)
->attach($iTipMessage->message->serialize(), "event.ics", $contentType);
try {
$failed = $this->mailer->send($message);
$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
if ($failed) {
$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => \implode(', ', $failed)]);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
}
} catch (\Exception $ex) {
$this->logger->logException($ex, ['app' => 'dav']);
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
Expand Down
7 changes: 4 additions & 3 deletions lib/private/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ public function send(Message $message): array {
try {
$this->getInstance($logger ?? null)->send($message->getMessage());
} catch (TransportExceptionInterface $e) {
$this->logger->logException($e);

# in case of exception it is expected that none of the mails has been sent
$failedRecipients = [];

Expand All @@ -111,7 +109,10 @@ public function send(Message $message): array {
}
});

return $failedRecipients;
$this->logger->logException($e, ['failed-recipients' => $recipients]);

# list of failed recipients is not added by intention to not accidentally disclose private data
throw new \RuntimeException("Failed to deliver email", 0, $e);
}

$allRecipients = [];
Expand Down
19 changes: 5 additions & 14 deletions settings/Controller/MailSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,12 @@ public function sendTestMail() {
$message->setFrom([$this->defaultMailAddress]);
$message->setSubject($this->l10n->t('test email settings'));
$message->setPlainBody('If you received this email, the settings seem to be correct.');
$failed = $this->mailer->send($message);
if (empty($failed)) {
return ['data' =>
['message' =>
(string) $this->l10n->t('Email sent')
],
'status' => 'success'
];
}

return [
'data' => [
'message' => (string) $this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', ['not delivered']),
$this->mailer->send($message);
return ['data' =>
['message' =>
(string) $this->l10n->t('Email sent')
],
'status' => 'error',
'status' => 'success'
];
} catch (\Exception $e) {
return [
Expand Down

0 comments on commit b7c4f0c

Please sign in to comment.