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

Catch errors when one email could not be sent #52

Merged
merged 1 commit into from
Oct 13, 2016
Merged
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
10 changes: 8 additions & 2 deletions lib/BackgroundJob/EmailNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ protected function runStep($limit, $sendTime) {
// Send Email
$default_lang = $this->config->getSystemValue('default_language', 'en');
$defaultTimeZone = date_default_timezone_get();

$deleteItemsForUsers = [];
foreach ($affectedUsers as $user) {
if (empty($userEmails[$user])) {
// The user did not setup an email address
Expand All @@ -118,11 +120,15 @@ protected function runStep($limit, $sendTime) {

$language = (!empty($userLanguages[$user])) ? $userLanguages[$user] : $default_lang;
$timezone = (!empty($userTimezones[$user])) ? $userTimezones[$user] : $defaultTimeZone;
$this->mqHandler->sendEmailToUser($user, $userEmails[$user], $language, $timezone, $sendTime);
if ($this->mqHandler->sendEmailToUser($user, $userEmails[$user], $language, $timezone, $sendTime)) {
$deleteItemsForUsers[] = $user;
} else {
$this->logger->debug("Failed sending activity mail to user '" . $user . "'.", ['app' => 'activity']);
}
}

// Delete all entries we dealt with
$this->mqHandler->deleteSentItems($affectedUsers, $sendTime);
$this->mqHandler->deleteSentItems($deleteItemsForUsers, $sendTime);

return sizeof($affectedUsers);
}
Expand Down
11 changes: 9 additions & 2 deletions lib/MailQueueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,12 @@ protected function getSenderData($setting) {
* @param string $lang Selected language of the recipient
* @param string $timezone Selected timezone of the recipient
* @param int $maxTime
* @return bool True if the entries should be removed, false otherwise
*/
public function sendEmailToUser($userName, $email, $lang, $timezone, $maxTime) {
$user = $this->userManager->get($userName);
if (!$user instanceof IUser) {
return;
return true;
}

list($mailData, $skippedCount) = $this->getItemsForUser($userName, $maxTime);
Expand Down Expand Up @@ -270,9 +271,15 @@ public function sendEmailToUser($userName, $email, $lang, $timezone, $maxTime) {
$message->setSubject((string) $l->t('Activity notification'));
$message->setPlainBody($emailText);
$message->setFrom([$this->getSenderData('email') => $this->getSenderData('name')]);
$this->mailer->send($message);

try {
$this->mailer->send($message);
} catch (\Exception $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always really bad 🙈 Then an exception is simply dropped - at least having it in debug mode visible would make this traceable.

Copy link
Member Author

@nickvergessen nickvergessen Oct 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's logged one step outside in lib/BackgroundJob/EmailNotification.php:

$this->logger->debug("Failed sending activity mail to user '" . $user . "'.", ['app' => 'activity']);

return false;
}

$this->activityManager->setCurrentUserId(null);
return true;
}

/**
Expand Down