예제 #1
0
 /**
  * Send a test email
  *
  * @param TBGRequest $request
  */
 public function runTestEmail(TBGRequest $request)
 {
     if ($email_to = $request->getParameter('test_email_to')) {
         try {
             if (TBGMailing::getModule()->sendTestEmail($email_to)) {
                 TBGContext::setMessage('module_message', TBGContext::getI18n()->__('The email was successfully accepted for delivery'));
             } else {
                 TBGContext::setMessage('module_error', TBGContext::getI18n()->__('The email was not sent'));
                 TBGContext::setMessage('module_error_details', TBGLogging::getMessagesForCategory('mailing', TBGLogging::LEVEL_NOTICE));
             }
         } catch (Exception $e) {
             TBGContext::setMessage('module_error', TBGContext::getI18n()->__('The email was not sent'));
             TBGContext::setMessage('module_error_details', $e->getMessage());
         }
     } else {
         TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Please specify an email address'));
     }
     $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'mailing')));
 }
 public function do_execute()
 {
     $this->cliEcho("Processing mail queue ... \n", 'white', 'bold');
     $limit = $this->getProvidedArgument('limit', null);
     $messages = TBGMailQueueTable::getTable()->getQueuedMessages($limit);
     $this->cliEcho("Email(s) to process: ");
     $this->cliEcho(count($messages) . "\n", 'white', 'bold');
     if ($this->getProvidedArgument('test', 'no') == 'no') {
         if (count($messages) > 0) {
             $mailer = TBGMailing::getModule()->getMailer();
             $processed_messages = array();
             $failed_messages = 0;
             try {
                 foreach ($messages as $message_id => $message) {
                     $retval = $mailer->send($message);
                     $processed_messages[] = $message_id;
                     if (!$retval) {
                         $failed_messages++;
                     }
                 }
             } catch (Exception $e) {
                 throw $e;
             }
             if (count($processed_messages)) {
                 TBGMailQueueTable::getTable()->deleteProcessedMessages($processed_messages);
                 $this->cliEcho("Emails successfully processed: ");
                 $this->cliEcho(count($messages) . "\n", 'green', 'bold');
                 if ($failed_messages > 0) {
                     $this->cliEcho("Emails processed with error(s): ");
                     $this->cliEcho($failed_messages . "\n", 'red', 'bold');
                 }
             }
         }
     } else {
         $this->cliEcho("Not processing queue...\n");
     }
 }