PHPackages                             ctsoftwarellc/laravel-mail-throttle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. ctsoftwarellc/laravel-mail-throttle

ActiveLibrary[Caching](/categories/caching)

ctsoftwarellc/laravel-mail-throttle
===================================

Distributed rate limiting for Laravel mail across multiple queue workers

1.1.0(5mo ago)2402↓21.4%MITPHPPHP ^8.2

Since Dec 18Pushed 5mo agoCompare

[ Source](https://github.com/ctsoftwarellc/laravel-mail-throttle)[ Packagist](https://packagist.org/packages/ctsoftwarellc/laravel-mail-throttle)[ RSS](/packages/ctsoftwarellc-laravel-mail-throttle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (3)Used By (0)

Laravel Mail Throttle
=====================

[](#laravel-mail-throttle)

Distributed rate limiting for Laravel mail across multiple queue workers.

Problem
-------

[](#problem)

Email providers have rate limits:

- **Resend**: 2/sec (free), 100/sec (pro)
- **Postmark**: 10/sec
- **SES**: 14/sec (default)
- **Mailgun**: Varies by plan

Their SDKs don't handle this. When you dispatch 1,000 notifications, your queue workers blast them out and you hit 429 errors.

Solution
--------

[](#solution)

This package provides:

- **Distributed throttling** via Redis - works across multiple Horizon workers
- **Opt-in per class** - add a trait to enable throttling
- **Config in mail.php** - rate limits live with your mailer config
- **Dynamic backoff with jitter** - prevents thundering herd at scale
- **Fail-safe** - configurable behavior when Redis is unavailable

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 10, 11, or 12
- Redis (required for distributed throttling)

Installation
------------

[](#installation)

```
composer require ctsoftwarellc/laravel-mail-throttle
```

Optionally publish the config:

```
php artisan vendor:publish --tag=mail-throttle-config
```

Configuration
-------------

[](#configuration)

Add rate limits to your mailers in `config/mail.php`:

```
'mailers' => [
    'resend' => [
        'transport' => 'resend',
        'rate_limit' => env('MAIL_RATE_LIMIT', 2),        // emails per window
        'rate_limit_per' => env('MAIL_RATE_LIMIT_PER', 1), // window in seconds
    ],

    'postmark' => [
        'transport' => 'postmark',
        'rate_limit' => 10,
        'rate_limit_per' => 1,
    ],

    // No rate_limit = no throttling (existing behavior preserved)
    'smtp' => [
        'transport' => 'smtp',
    ],
],
```

Usage
-----

[](#usage)

### Notifications

[](#notifications)

Add the `ThrottlesMail` trait to your queued notifications:

```
