Skip to content
Intercepts emails being sent by Laravel. Great for local mail development.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
src
tests
.editorconfig
.gitattributes
.gitignore
.scrutinizer.yml
.travis.yml
CHANGELOG.md
LICENSE.md
README.md
composer.json
phpunit.xml.dist

README.md

Laravel Message Interceptor

Latest Version on Packagist Build Status Quality Score Software License

This Laravel package helps to intercept e-mails and sends them to another recipient (or recipients) in a local environment.

Laravel ships with one way of intercepting emails in a local environment. However, this packages gives you a little bit more flexibility, such as whitelisting emails and domains in a local environment, preserving CC and BCC recipients, etc.

This hopefully helps to make the testing experience in email-centric workflows a little less painful for developers working locally.

Install

Via Composer

$ composer require mozammil/laravel-message-interceptor --dev

Because of package auto-discovery, this should automatically register your ServiceProvider.

Configuration

To publish the config file, you should do the following:

$ php artisan vendor:publish

The config file will be copied to config/message-interceptor.php. It should give you an idea of what's possible with the package.

<?php

return [

    /**
     * Whether or not the emails being sent should
     * be intercepted.
     */
    'enabled' => env('MESSAGE_INTERCEPTOR_ENABLED', false),

    /**
     * The intercepted emails will be sent
     * to this address instead. If the address
     * is not send, an exception will be thrown
     */
    'to' => [
        'address' => env('MESSAGE_INTERCEPTOR_ADDRESS', ''),
        'name' => env('MESSAGE_INTERCEPTOR_NAME', '')
    ],

    /**
     * By default, we will clear the recipients that are
     * cc'ed in the message. If you want to preserve the
     * cc'ed recipients, set this to true
     */
    'preserveCc' => env('MESSAGE_INTERCEPTOR_PRESERVE_CC', false),

    /**
     * By default, we will clear the recipients that are
     * bcc'ed in the message. If you want to preserve the
     * bcc'ed recipients, set this to true
     */
    'preserveBcc' => env('MESSAGE_INTERCEPTOR_PRESERVE_BCC', false),

    /**
     * The following addresses will also be CC'ed
     * when the email is intercepted and sent.
     */
    'cc' => [],

    /**
     * The following addresses will also be BCC'ed
     * when the email is intercepted and sent.
     */
    'bcc' => [],

    /**
     * Whitelisted email recipients.
     */
    'whitelist' => [
        /**
         * Email addresses in the list below will
         * not be filtered out
         */
        'emails' => [],

        /**
         * Email address matching the domain in
         * the list below will not be filtered out
         */
        'domains' => []
    ]
];

For the package to work appropriately, it is fundamental that the following is configured in your .env file. By default, no emails will be intercepted.

MESSAGE_INTERCEPTOR_ADDRESS=hello@example.com
MESSAGE_INTERCEPTOR_ENABLED=true

Additional Information

Whenever an e-mail is intercepted, a Mozammil\LaravelMessageInterceptor\Events\MessageIntercepted::class event is also dispatched. You could then retrieve the original underlying Swift_Message from the event.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email hello@moz.im instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

You can’t perform that action at this time.