How to set high, low and medium priority email using queue?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# How to Set High, Low, and Medium Priority Email Sending Using Queues in Laravel As a senior developer working with high-throughput applications, managing asynchronous tasks—especially time-sensitive communications like email delivery—is critical. When dealing with email job dispatching from here, the need for priority handling becomes paramount. While Laravel’s queue system is incredibly robust, understanding how to implement true priority sorting requires moving beyond simple FIFO (First-In, First-Out) processing and leveraging the queuing infrastructure effectively. The initial confusion often arises because the concept of "priority" isn't natively handled by the underlying queue driver itself; rather, it’s managed by how we configure our queues and workers. Let’s break down the practical way to achieve high, low, and medium priority email sending in a Laravel environment. ## Understanding the Limitation of Simple Queuing You correctly identified that simply passing a comma-separated list like `--queue=high,default` often fails if the connection configuration itself is strictly tied to a single queue name (like `'low'` or `'database'`). This happens because the worker process pulls jobs based on the queues it is explicitly told to listen to. A standard queue, whether using the database driver or Redis, processes messages in the order they were received. To introduce priority, we must create separate channels for those priorities. ## The Solution: Implementing Priority Through Multiple Queues The most reliable and scalable approach in Laravel is to define distinct queues for each priority level. This allows you to dedicate specific worker processes to handle high-priority tasks immediately, bypassing the backlog of lower-priority jobs. ### Step 1: Configure Distinct Queue Connections First, we need to ensure our queue connections are set up to handle these different priorities. When setting up your application, define separate queues in your `config/queue.php` or via your database configuration. For instance, if you are using the database driver (as suggested by your setup), you will manage these as distinct tables or queues: ```php // Example of how connections might be defined conceptually 'connections' => [ 'database' => [ 'driver' => 'database', 'table' => 'jobs', // All jobs land here initially 'queue' => 'default', ], 'high_priority' => [ 'driver' => 'database', 'table' => 'jobs', 'queue' => 'high', // Dedicated queue for urgent emails ], 'low_priority' => [ 'driver' => 'database', 'table' => 'jobs', 'queue' => 'low', // Dedicated queue for bulk emails ], ], ``` ### Step 2: Dispatching Jobs with Priority When dispatching an email job, you explicitly tell Laravel which priority channel it belongs to by specifying the connection/queue name. This aligns perfectly with how you dispatched your registration and password reset jobs using `onConnection('Register')`. For high-priority emails (like password resets or critical alerts), you dispatch them directly to the dedicated high queue: ```php use App\Jobs\SendActivationEmail; // Dispatching a high-priority email $job = new SendActivationEmail($Data); $job->onConnection('high_priority'); // Explicitly assign to the high queue dispatch($job); ``` For lower-priority bulk emails, you dispatch them to the low queue: ```php // Dispatching a low-priority email $job = new SendBulkNewsletterEmail($User); $job->onConnection('low_priority'); // Assign to the low queue dispatch($job); ``` ### Step 3: Running Prioritized Workers Instead of running a single, monolithic worker that sweeps through all queues, you run specialized workers dedicated to specific priority levels. This ensures that high-priority tasks are picked up instantly without waiting for the lower-priority batch to finish processing. You would start separate command processes for each queue: ```bash # Worker dedicated to handling urgent emails immediately php artisan queue:work --queue=high_priority # Worker dedicated to handling standard/bulk emails php artisan queue:work --queue=low_priority ``` By segmenting your workload this way, you gain granular control over email delivery latency. This layered approach is a core principle of building efficient background processing systems, much like the job dispatching concepts detailed on https://laravelcompany.com regarding robust task management. ## Conclusion Setting high, low, and medium priorities for email queues is achieved not by modifying the queue driver itself, but by structuring your application to use multiple, dedicated queues. By defining separate connections for 'high', 'medium', and 'low' priority, and then running specialized workers against those queues, you ensure that critical communications are processed with minimal delay. This strategy transforms a simple queue into a sophisticated prioritization system, significantly improving the responsiveness of your application.