Skip to content

Commit

Permalink
Merge pull request #13931 from nextcloud/backport/12636/stable14
Browse files Browse the repository at this point in the history
[stable14] handle mail send error gracefully
  • Loading branch information
rullzer authored Jan 31, 2019
2 parents 1572b26 + a7c897b commit 1fd8e68
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,29 +692,32 @@ public function createShare(\OCP\Share\IShare $share) {
$emailAddress,
$share->getExpirationDate()
);
$this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']);
$this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']);
} else {
$this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']);
$this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']);
}
} else {
$this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']);
$this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']);
}
} else {
$this->logger->debug('Share notification not send because mailsend is false.', ['app' => 'share']);
$this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']);
}
}

return $share;
}

/**
* Send mail notifications
*
* This method will catch and log mail transmission errors
*
* @param IL10N $l Language of the recipient
* @param string $filename file/folder name
* @param string $link link to the file/folder
* @param string $initiator user ID of share sender
* @param string $shareWith email address of share receiver
* @param \DateTime|null $expiration
* @throws \Exception If mail couldn't be sent
*/
protected function sendMailNotification(IL10N $l,
$filename,
Expand Down Expand Up @@ -773,7 +776,15 @@ protected function sendMailNotification(IL10N $l,
}

$message->useTemplate($emailTemplate);
$this->mailer->send($message);
try {
$failedRecipients = $this->mailer->send($message);
if(!empty($failedRecipients)) {
$this->logger->error('Share notification mail could not be sent to: ' . implode(', ', $failedRecipients));
return;
}
} catch (\Exception $e) {
$this->logger->logException($e, ['message' => 'Share notification mail could not be sent']);
}
}

/**
Expand Down

0 comments on commit 1fd8e68

Please sign in to comment.