Ejemplo n.º 1
0
 /**
  * Handler
  *
  * @param \Illuminate\Contracts\Mail\Mailer $mailer
  * @param \Illuminate\Contracts\View\Factory $view
  * @param \Illuminate\Contracts\Validation\Factory $validator
  * @throws \Exception
  * @return void
  */
 public function handle(Mailer $mailer, Factory $view, Validator $validator)
 {
     $queue = $this->messageQueue;
     $queue->status = 'in_processes';
     $queue->save();
     $queue->load('event', 'event.template');
     $parameters = array_merge_recursive($queue->event->template->parameters, $queue->event->parameters, $queue->parameters);
     $messageParameters = array_dot($this->getMessageParameters($validator, $parameters['message']));
     $renderView = $queue->event->template->getRender($parameters['view']);
     $mailer->send('message-sender::providers.plain', ['content' => $renderView], function ($message) use($parameters, $messageParameters) {
         $message->from($messageParameters['from.address'], $messageParameters['from.name']);
         $message->to($messageParameters['to.address'], $messageParameters['from.name']);
         $message->subject($parameters['provider']['subject']);
         if (isset($parameters['provider']['headers'])) {
             $mailHeaders = $message->getSwiftMessage()->getHeaders();
             foreach ($parameters['provider']['headers'] as $header) {
                 $mailHeaders->addTextHeader($header['name'], $header['value']);
             }
         }
     });
     if (count($mailer->failures()) > 0) {
         throw new \Exception('Mail send failed.');
     } else {
         $queue->status = 'sent';
         $queue->save();
     }
 }
Ejemplo n.º 2
0
 /**
  * Get the array of failed recipients.
  *
  * @return array
  */
 public function failures()
 {
     return $this->mailer->failures();
 }