Retrieve Mailgun message-id from Laravel notifications
Hello there,
I'm working on a task where the client wants to check whether the Notification(Email) is delivered to the recipient or not. I'm using mailgun SMTP details and also configured the webhook from mailgun.
Now I need only the message-id from the Laravel notifications so I can cross-verify it with the response I receive from the Mailgun webhook.
Using Laravel Notification I never needed to get the message-id, but using an event I needed, maybe the code can help you:
<?php
namespace App\Listeners;
use Illuminate\Mail\Events\MessageSent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class EmailMensagemEnviada
{
/**
* Handle the event.
*
* @param MessageSent $event
* @return void
*/
public function handle(MessageSent $event)
{
//message-id
$event->message->getId();
}
}
@elton869 Thanks for your reply, But as I described above I am sending emails using Laravel notifications and also established a webhook for Mailgun. So, I want to track whether the email has been delivered or not. So to do cross-verification I need a message-id that has been returned from the Mailgun. (or something using which I can match).
I found the solution. We have to add our custom headers using withSymfonyMessage and in webhook response, mailgun will return it in the user-variables object. I've also used ['database','mail'] in the Laravel notification within via method.
https://laravel.com/docs/10.x/notifications#customizing-the-symfony-message