How to Queue Laravel Email Verification – Fast Tips

Valerio Barbera

Queue email is a standard practice in any application I build. There is no project that starts without a Redis instance.

If you decided to use the built-in Laravel email verification you probably noticed that the email containing the verification link is prebuilt inside the framework. What if you want to queue it?When you add the Illuminate\Contracts\Auth\MustVerifyEmail interface to the User model it will bring a couple of methods to manage email verification:

namespace Illuminate\Contracts\Auth;

interface MustVerifyEmail
{
    /**
     * Determine if the user has verified their email address.
     *
     * @return bool
     */
    public function hasVerifiedEmail();

    /**
     * Mark the given user's email as verified.
     *
     * @return bool
     */
    public function markEmailAsVerified();

    /**
     * Send the email verification notification.
     *
     * @return void
     */
    public function sendEmailVerificationNotification();

    /**
     * Get the email address that should be used for verification.
     *
     * @return string
     */
    public function getEmailForVerification();
}

Laravel gets the instance of the Mail class to use calling the method: sendEmailVerificationNotification()

The default implementation of this method is in the MustVerifyEmail trait:

namespace Illuminate\Auth;

use Illuminate\Auth\Notifications\VerifyEmail;

trait MustVerifyEmail
{
    // ... 

    /**
     * Send the email verification notification.
     *
     * @return void
     */
    public function sendEmailVerificationNotification()
    {
        $this->notify(new VerifyEmail);
    }

    // ... 
}

Finally we have found the Illuminate\Auth\Notifications\VerifyEmail class used by the framework to notify the verification link to the user.

namespace Illuminate\Auth\Notifications;

class VerifyEmail extends Notification
{
	// ...
}

If you want to learn more on Laravel email verification system, you can take a look at the article below:

For more technical articles you can follow me on Linkedin or X.

Queue email verification

As you can see from the snippet above it is a standard notification, so it will be sent synchronously during the HTTP requests of the registration process. 

Queuing this email is important to avoid the registration process being slow, or even breaks for an error communicating with the mailing system.

We can create a custom email on our project that extends this original notification class adding the queue properties:

namespace App\Mails;

use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;

class QueuedVerifyEmail extends VerifyEmail implements ShouldQueue
{
    use Queueable;
}

Now you must override the method on the User model to notify using this custom queueable notifications:

namespace App\Models;

use App\Domains\Organization\Notifications\QueuedVerifyEmail;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements MustVerifyEmail
{
	// ...
	
	public function sendEmailVerificationNotification()
    {
        $this->notify(new QueuedVerifyEmail());
    }
	
	// ... 
}

For more technical articles you can follow me on Linkedin or X.

Monitor your Laravel application for free

Inspector is a Code Execution Monitoring tool specifically designed for software developers. You don’t need to install anything on the infrastructure, just install the Laravel package and you are ready to go.

If you are looking for HTTP monitoring, database query insights, and the ability to forward alerts and notifications into your preferred messaging environment try Inspector for free. Register your account.

Or learn more on the website: https://inspector.dev

Related Posts

How to Stop a Streamed AI Response Mid-Flight in Neuron AI v3

One thing I didn’t anticipate when building Neuron AI was how many edge cases would surface not from the AI integration itself, but from the UI layer sitting on top of it. Developers don’t just want agents that work. They want agents that feel right to use. And the moment you start building chat interfaces

Conversational Data Collection: Introducing AIForm

One of the more interesting things about building an open-source framework is that the community often knows what to build next before you do. When I started Neuron AI, I had a fairly clear picture in my head of the core primitives: agents, tools, workflows, structured output. What I didn’t fully anticipate was how quickly

Neuron AI Now Supports ZAI — The GLM Series Is Worth Your Attention

There’s a pattern I’ve noticed over the past year while working on Neuron AI: the decisions that matter most are rarely about chasing trends. They’re about quietly recognizing something that works, testing it seriously, and integrating it so that other developers can benefit without having to do that work themselves. That’s the honest story behind