Skip to content

Commit

Permalink
Do not show 500 error if email credentials are wrong, fixes #37 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbohal authored Nov 2, 2019
1 parent af269d5 commit b3d1f85
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public function indexAction()
*/
public function sendAllAction()
{
(new Service_Email())->sendQueued();
$this->_flashMessenger->addMessage('All emails have been successfully sent.', 'success');
if ((new Service_Email())->sendQueued()) {
$this->_flashMessenger->addMessage('All emails have been successfully sent.', 'success');
} else {
$this->_flashMessenger->addMessage('There was an error when sending the emails.', 'error');
}
$this->redirect($this->view->url(['action' => 'index']), ['prependBase' => false]);
}
}
4 changes: 3 additions & 1 deletion application/services/Cron/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Service_Cron_Mail extends Service_Cron
*/
public function execute()
{
(new Service_Email())->sendQueued();
if (!(new Service_Email())->sendQueued()) {
throw new Exception('There was an error when sending the emails');
}
}
}
23 changes: 11 additions & 12 deletions application/services/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ public function queueForSend(Dbjr_Mail $mail)
return $this;
}

/**
* Sends all unsent emails
* @return Service_Email Provides fluent interface
*/
public function sendQueued()
public function sendQueued(): bool
{
$mailModel = new Model_Mail();
$emails = $mailModel->fetchAll(
Expand Down Expand Up @@ -51,14 +47,17 @@ public function sendQueued()
$mailer->addBcc($recipient->email, $recipient->name);
}
}
$mailer->send();

$mailModel->update(
array('time_sent' => Zend_Date::now()->toString('YYYY-MM-dd HH:mm:ss')),
array('id=?' => $email->id)
);
try {
$mailer->send();
$mailModel->update(
array('time_sent' => Zend_Date::now()->toString('YYYY-MM-dd HH:mm:ss')),
array('id=?' => $email->id)
);
} catch (Zend_Mail_Protocol_Exception $e) {
return false;
}
}

return $this;
return true;
}
}

0 comments on commit b3d1f85

Please sign in to comment.