예제 #1
0
 /**
  * Execute the console command.
  */
 public function handle()
 {
     // Send admin created e-mails.
     $emails = Email::where('sent', false)->where('ready', true)->where('time', '<', date('U'))->get();
     $this->info('There are ' . $emails->count() . ' queued e-mails.');
     foreach ($emails as $email) {
         $this->info('Sending e-mail <' . $email->subject . '>');
         $email->ready = false;
         $email->sent = true;
         $email->sent_to = $email->recipients()->count();
         $email->save();
         foreach ($email->recipients() as $recipient) {
             Mail::queue('emails.manualemail', ['body' => $email->parseBodyFor($recipient), 'attachments' => $email->attachments, 'destination' => $email->destinationForBody(), 'user_id' => $recipient->id], function ($message) use($email, $recipient) {
                 $message->to($recipient->email, $recipient->name)->from($email->sender_address . '@' . config('proto.emaildomain'), $email->sender_name)->subject($email->subject);
                 foreach ($email->attachments as $attachment) {
                     $message->attach($attachment->generateLocalPath(), ['as' => $attachment->original_filename, 'mime' => $attachment->mime]);
                 }
             });
         }
         $this->info('Sent to ' . $email->recipients()->count() . ' people.');
     }
     $this->info($emails->count() > 0 ? 'All e-mails sent.' : 'No e-mails to be sent.');
 }
예제 #2
0
 private function updateEmailDestination(Email $email, $type, $lists = null)
 {
     switch ($type) {
         case 'users':
             $email->to_user = true;
             $email->to_member = false;
             $email->to_list = false;
             $email->lists()->sync([]);
             break;
         case 'members':
             $email->to_user = false;
             $email->to_member = true;
             $email->to_list = false;
             $email->lists()->sync([]);
             break;
         case 'lists':
             $email->to_user = false;
             $email->to_member = false;
             $email->to_list = true;
             $email->lists()->sync($lists);
             break;
         default:
             abort(500, 'Invalid e-mail destination');
             break;
     }
     $email->save();
 }