Esempio n. 1
0
 /**
  * Find a potential queue and if found, send each email one by one
  *
  * @return void
  */
 public function run()
 {
     // The consumer ID will be placed against all pending emails
     $consumerId = uniqid();
     // Inform the user of the consumer id before proceeding
     $this->_renderHeader();
     $this->out("   Consumer ID: {$consumerId}", 2);
     // Search for pending emails and apply the consumer id to them
     if (!$this->EmailQueue->updatePending($consumerId)) {
         return $this->out('   Found 0 items in queue, exiting ...', 2);
     }
     // Find all the emails which were assigned with the consumer id
     $pendingItems = $this->EmailQueue->pendingItems($consumerId);
     $this->out('   Found ' . count($pendingItems) . ' items in queue, dispatching:', 2);
     // Loop through each email one by one
     foreach ($pendingItems as $item) {
         // Inform the user which email is being processed currency
         $this->out('    ' . str_pad("# {$item['EmailQueue']['id']}", 7, ' ') . '  ' . str_pad($item['EmailQueue']['to'] . '  ', 40, '.'), false);
         // Use your preferred email config here
         $email = new CakeEmail('custom');
         // Attempt to send the serialized email using the above config, log the status
         if ($email->transportClass()->send(unserialize($item['EmailQueue']['serialized']))) {
             $status = 1;
             $this->out('  [<success> OK </success>]', 2);
         } else {
             $status = 2;
             $this->out('  [<warning> !! </warning>]', 2);
         }
         // Attempt to update the email queue record with the new status
         if (!$this->EmailQueue->saveItemStatus($item['EmailQueue']['id'], $status)) {
             throw new Exception("Saving queue item failed, orphan created for ID #{$item['EmailQueue']['id']}!");
         }
     }
 }
 public function execute()
 {
     if (empty($this->args[0]) || empty($this->args[1])) {
         throw new MailqueueArgumentException('Rquired arguments "queue-name", "transport configuration name"');
     }
     $queueMailer = new CakeEmail($this->args[0]);
     $realMailer = new CakeEmail(empty($this->args[1]) ? null : $this->args[1]);
     $queueMailer->transportClass()->flush($realMailer);
 }