【发布时间】:2021-01-21 21:00:44
【问题描述】:
我已经被困在这很长一段时间了。我正在尝试通过回调函数提取电子邮件的 messageID 并存储在数据库中以备后用。我在基于 gmail 的服务器中模拟了相同的条件,它可以工作。但我不认为电子邮件服务器与任何事情有关。这是我尝试提取 messageID 的可邮寄类:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use App\EmailLog;
use App\EmailLogDetail;
class GenericSendEmailMailable extends Mailable
{
//use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
private $applicationTemplate;
public $subject;
private $data;
private $emailLogId;
public function __construct(String $applicationTemplate,Array $data,String $subject, $emailLogId)
{
//
$this->applicationTemplate = $applicationTemplate;
$this->data = $data;
$this->subject = $subject;
$this->emailLogId = $emailLogId;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$emailLogId = $this->emailLogId;
$view = $this->applicationTemplate;
$data = $this->data;
$subject = $this->subject;
return $this->subject($subject)
->view($view,$data)
->withSwiftMessage(function ($message) use ($emailLogId){
$emailLog = EmailLog::where('id', $emailLogId)->first();
if(isset($emailLog->email_log_details)){
foreach($emailLog->email_log_details as $emailLogDetail){
$emailLogDetail->message_id = $message->getId();
$emailLogDetail->save();
}
}
});
}
}
这里是 $message->getId();应该可以正常工作,但是当我发送邮件并检查数据库时,这不是原因,未存储消息 ID。顺便说一句,电子邮件发送操作是作为作业分派的。关于为什么这不起作用的任何想法?
【问题讨论】:
-
查看 storage/log/laravel.log 中的日志