Reputation: 53
I've been trying to get "SMTP response code (e.g. 250, 530, etc.)" in my project using Laravel5.6 & Amazon SES, but eventually I couldn't find a way to do it.
Actually, I could get the "Message ID" which is published by SES... but how can I get RAW response code?
Here's what I've tried to get Message ID from mails sent.
1) Register "LogSentMessage" listener to "MessageSent" event, which would be fired when emails are sent.
protected $listen = [
'Illuminate\Mail\Events\MessageSent' => [
'App\Listeners\LogSentMessage',
],
];
2) Get Swift_message object in "App\Listeners\LogSentMessage" listener file
public function handle(MessageSent $event)
{
dd($event->message); //I could get an object containing email data
// $event->message->getId(); gives me the Message ID.
}
If anyone knows how to and let me share it, I would be really appreciated.
Thanks.
Upvotes: 1
Views: 1396
Reputation: 1273
You were on the right track.
The best/only way I found to get the MessageId is by wading through the headers of the sent message.
Inside the handle()
function of your App\Listeners\LogSentMessage
you'll be able to get the MessageId like so:
public function handle(MessageSent $event)
{
$message_id = $event->message
->getHeaders()
->get('x-ses-message-id')
->getValue();
}
Upvotes: 2