Ejemplo n.º 1
0
 public function send(MailMessage $mailMessage)
 {
     $from = $mailMessage->getFrom();
     config(['mail.host' => $this->host, 'mail.username' => $this->username, 'mail.password' => $this->password, 'mail.port' => $this->port, 'mail.encryption' => $this->protocol, 'mail.from' => ['address' => $from['email'], 'name' => $from['name']]]);
     $attempt = SenderAttempt::forceCreate(['sender_id' => $this->id, 'list_member_id' => $mailMessage->id, 'status' => 'pendding']);
     $status = Mail::raw($mailMessage->getMessage(), function ($message) use($mailMessage) {
         $to = $mailMessage->getDestinatary();
         $message->to($to['email'], $to['name']);
         $message->subject($mailMessage->getSubject());
         $message->setBody($mailMessage->getMessage(), 'text/html');
         //$message->from('telmo.riofrio@funiber.org', 'Telmo Riofrio');
         //$message->sender('telmo.riofrio@funiber.org', 'Telmo Riofrio');
         //$message->cc($address, $name = null);
         //$message->bcc($address, $name = null);
         $message->replyTo('telmo.riofrio@funiber.org', 'Telmo Riofrio replicar');
         //$message->priority($level);
         //$message->attach($pathToFile, array $options = []);
         // Attach a file from a raw $data string...
         //$message->attachData($data, $name, array $options = []);
         // Get the underlying SwiftMailer message instance...
         //$message->getSwiftMessage();
     });
     $status ? $mailMessage->complete() : $mailMessage->failure();
     $attempt->status = 'ok';
     $attempt->save();
     return $status;
 }
Ejemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMailMessages()
 {
     return $this->hasMany(MailMessage::className(), ['author_id' => 'id']);
 }