Search by

imarc / mailgate

daveanastasi

Whitelist outgoing mail recipients in Laravel—filter To, Cc, and Bcc before send and cancel when no allowed addresses remain.

Package info

github.com/imarc/mailgate

pkg:composer/imarc/mailgate

Statistics

Installs: 9

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.2 2026-11-13 22:10 UTC

This package is auto-updated.

Last update: 2026-11-13 22:10:36 UTC


README

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.

Why Mailgate?

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.

Behavior

  1. Disabled — message unchanged; send proceeds.
  2. 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.
  3. If no recipients remain, the send is canceled.
  4. Debug logs record stripped addresses, canceled sends, and successful sends.

Installation

composer require imarc/mailgate

Laravel auto-discovers MailgateServiceProvider and registers the listener on Illuminate\Mail\Events\MessageSending.

Optional — publish config:

php artisan vendor:publish --tag=mailgate-config

Configuration

Env Purpose
MAILGATE_ENABLED true / false
MAILGATE_ADDRESSES Comma-separated exact email addresses

Config keys (config/mailgate.php):

  • mailgate.enabled
  • mailgate.addresses — array of strings

Example (staging)

MAIL_MAILER=mailgun
MAILGATE_ENABLED=true
MAILGATE_ADDRESSES="you@imarc.com,team@imarc.com"

Leave MAILGATE_ENABLED false (or unset) in production.

License

MIT