Coder Social home page Coder Social logo

laravel-mailman's Introduction

Travis Packagist Packagist StyleCI Scrutinizer

"Mailman" mail driver for Laravel 5.2+ which allows email delivery to be restricted by environment but allowed for specific recipients.

Installation

Begin by installing the package through Composer. Run the following command in your terminal:

composer require qodeboy/laravel-mailman "5.2.*"

Once composer is done, add the package service provider in the providers array in config/app.php:

Qodeboy\Mailman\MailManServiceProvider::class,

Then publish the config file:

php artisan vendor:publish --provider="Qodeboy\Mailman\MailmanServiceProvider"

Change MAIL_DRIVER to mailman in your .env file:

MAIL_DRIVER=mailman

Finally, run migrations:

php artisan migrate

How it works

For every email sent this package will:

  • Check if current application environment is allowed to send emails.
  • If environment if denied, check if all of recipients are in the exception list.
  • Passe email through only if environment is allowed to send emails, or all of the recipients are in exception list.
  • Log email to database or filesystem (if configured to do so) along with it's status (allowed/denied).
  • Send email through configured "delivery" driver.

Configuration

Delivery driver

Delivery driver used to send emails which passed all checks is configured in mailman.delivery.driver option:

/*
 * Driver which will be used to deliver email if email
 * is allowed to send out.
 *
 * Allowed any driver as accepted by mail.driver core
 * config parameter.
 */
'driver' => 'log',

You can use any driver name here (except of mailman) which Laravel is aware of.

Allowed environments

To configure which environments are allowed to send emails, check mailman.delivery.environments option:

/*
 * List of environments which allowed to send emails.
 */
'environments' => [
    'production'
],

Each environment added here is allowed to send emails.

Allowed recipients

If you want to lock down environment but still allow some recipients to receive emails, add those addresses to mailman.delivery.recipients list:

/*
 * List of recipients which are allowed to receive
 * emails even if environment forbids email delivery.
 */
'recipients' => [],

Logging

By default this package will log every email which tries to go through into database. This is configured in mailman.log option:

/*
 * Configuration for email logging.
 */
'log' => [
    
    /*
     * Whatever email logging should be enabled or not.
     */
    'enabled' => true,

    /*
     * Storage to use for email log.
     * Possible values are 'database', 'filesystem'.
     */
    'storage' => 'database',
],

If you want to change log storage to simple filesystem log, change mailman.log.storage option to filesystem. Filesystem path where to store logs is explained below. If you want to completely turn off logging, just change mailman.delivery.enabled to false.

Logging storage

To customize where each logging driver is storing email logs, check mailman.storage option:

/*
 * Storage configuration.
 */
'storage' => [
    /*
     * Configuration for which database table should
     * be used for email logging.
     */
    'database' => [
        'table' => 'mailman_messages',
    ],

    /*
     * Configuration for where to store logged email messages.
     * Relative to the storage_path().
     */
    'filesystem' => [
        'path' => 'mailman'
    ]
],

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.