Every email message and notification Laravel sends have a set of pre-defined headers.
One of those is Message-ID, which is automatically generated for each new email. By default, it looks like this:
Message-ID: <653a2dfb31fe1e58236a367b0c139a3c@swift.generated>
While this doesn't do any serious damage to your email deliverability, it's a good practice to have your own domain name in this header. You can achieve this by following this short tutorial.
1. Edit the file config/mail.php
and define your domain near the end:
'domain' => 'yourdomain.com',
2. In the command line, create a new listener:
php artisan make:listener -e 'Illuminate\Mail\Events\MessageSending' MessageSendingListener
3. Edit the newly created listener and make it look as follows (do NOT implement ShouldQueue
):
<?php
/**
* Set the domain part in the message-id generated by Swift Mailer
*/
namespace App\Listeners;
use Illuminate\Mail\Events\MessageSending;
use Swift_Mime_IdGenerator;
class MessageSendingListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param MessageSending $event
*
* @return void
*/
public function handle(MessageSending $event)
{
$event->message->setId((new Swift_Mime_IdGenerator(config('mail.domain')))->generateId());
}
}
4. Register the listener in app/Providers/EventServiceProvider.php
:
protected $listen = [
// [...]
\Illuminate\Mail\Events\MessageSending::class => [
\App\Listeners\MessageSendingListener::class,
],
];
That's it, enjoy!