public function execute($lastRunDt = null) { $eq = new Ot_Model_DbTable_EmailQueue(); $messages = $eq->getWaitingEmails(20); $logger = Zend_Registry::get('logger'); foreach ($messages as $m) { try { $m['zendMailObject']->send(); $m['status'] = 'sent'; $m['sentDt'] = time(); } catch (Exception $e) { $m['status'] = 'error'; } $where = $eq->getAdapter()->quoteInto('queueId = ?', $m['queueId']); $eq->update($m, $where); $logOptions = array('attributeName' => 'queueId', 'attributeId' => $m['queueId']); $logger->setEventItem('attributeName', 'queueId'); $logger->setEventItem('attributeId', $m['queueId']); $logger->log('Mail Sent', Zend_Log::INFO); } }
/** * Action called when a trigger is executed. * * @param array $data */ public function dispatch(array $data) { $eq = new Ot_Model_DbTable_EmailQueue(); $mail = new Zend_Mail(); $to = explode(',', $data['to']); $toFiltered = array(); foreach ($to as $t) { if (trim($t) != '') { $toFiltered[] = trim($t); } } if (count($toFiltered) == 0) { return; } foreach ($toFiltered as $t) { $mail->addTo($t); } $mail->setFrom($data['from'], $data['fromName']); $mail->setSubject($data['subject']); $mail->setBodyText($data['body']); $eData = array('zendMailObject' => $mail, 'attributeName' => 'triggerActionId', 'attributeId' => $data['triggerActionId']); $eq->queueEmail($eData); }
/** * Deletes an email from the queue */ public function deleteAction() { $eq = new Ot_Model_DbTable_EmailQueue(); $queueId = $this->_getParam('queueId', null); if (is_null($queueId)) { throw new Ot_Exception_Input('msg-error-queueIdNotSet'); } $email = $eq->find($queueId); if (is_null($email)) { throw new Ot_Exception_Data('msg-error-noQueue'); } if ($this->_request->isPost()) { $where = $eq->getAdapter()->quoteInto('queueId = ?', $queueId); $eq->delete($where); $this->_helper->messenger->addSuccess('ot-emailqueue-delete:success'); $this->_helper->redirector->gotoRoute(array('controller' => 'emailqueue'), 'ot', true); } else { throw new Ot_Exception_Access('You are not allowed to access this method directly'); } }