Laravel package that whitelists outgoing mail recipients (To, Cc, Bcc) in non-production environments. When enabled, only configured addresses survive; if every recipient is removed, the send is canceled.
Staging and QA often use real mail transports (Mailgun, SES, etc.) while the app still generates notifications with production-like recipient lists. Mailgate hooks Laravel’s pre-send mail event so you can limit delivery to your team without changing application code.
- Disabled — message unchanged; send proceeds.
- Enabled — each To/Cc/Bcc address must match an entry in the allow list exactly (case-insensitive; no domain wildcards). Non-matching addresses are stripped.
- If no recipients remain, the send is canceled.
- Debug logs record stripped addresses, canceled sends, and successful sends.
composer require imarc/mailgateLaravel auto-discovers MailgateServiceProvider and registers the listener on Illuminate\Mail\Events\MessageSending.
Optional — publish config:
php artisan vendor:publish --tag=mailgate-config| Env | Purpose |
|---|---|
MAILGATE_ENABLED |
true / false |
MAILGATE_ADDRESSES |
Comma-separated exact email addresses |
Config keys (config/mailgate.php):
mailgate.enabledmailgate.addresses— array of strings
MAIL_MAILER=mailgun
MAILGATE_ENABLED=true
MAILGATE_ADDRESSES="you@imarc.com,team@imarc.com"Leave MAILGATE_ENABLED false (or unset) in production.
MIT