Skip to content

Quickly send test emails using commands in Laravel applications

License

Notifications You must be signed in to change notification settings

resohead/laravel-test-mail

Repository files navigation

Laravel Test Mail

Latest Version on Packagist Build Status Code Coverage Quality Score Maintainability Total Downloads

A simple package to send test emails from artisan commands in Laravel applications. Ideal for checking mail and queue configurations without any setup.

Installation

You can install the package via composer:

composer require resohead/laravel-test-mail

The package will automatically register itself.

Optionally publish the config file to enable presets:

php artisan vendor:publish --provider="Resohead\LaravelTestMail\LaravelTestMailServiceProvider" --tag="config"

Basic Usage

To send a test email run the following artisan command:

php artisan mail:test

By default this will:

  • send to the 'from' address defined in your mail config,
  • use your default mail driver,
  • synchronous processing

Alternatively you have four other options in the command signature:

  • set the email address,
  • change the mail driver,
  • enable for queuing (and set the queue name)
  • change the queue connection
  • select a preset

Changing the mail driver and running through a queue might require the queue worker to be started/reset.

Command Line Options

Send to specified email

php artisan mail:test name@example.com

Send to specified email on default queue

php artisan mail:test name@example.com --queue

Send via log driver

php artisan mail:test --driver=log

Send to the 'emails' queue on default connection

php artisan mail:test --stack=emails

There is no need to set the --queue flag when using the stack argument

Send using 'sqs' queue connection

php artisan mail:test --connection=sqs

There is no need to set the --queue flag when using the connection argument

Send using the SMTP driver via the 'emails' queue on the 'redis' connection

php artisan mail:test name@example.com --driver=smtp --connection=redis --stack=emails

Queues

You might need to start the your queue if using the connection option, for example

php artisan queue:work sqs --queue:emails

Presets

You can also configure presets to group command line options. The values defined in each preset will be merged with the command line values and your default mail and queue configuration.

Example config\mail-test.php

'presets' => [

        'example1' => [
            'recipient' => 'preset1@example.com',
            'queue' => true
        ],

        'example2' => [
            'driver' => 'log',
            'stack' => 'emails'
        ],

        'example3' => [
            'recipient' => env('EMAIL_TO', 'preset3@example.com'),
            'driver' => 'smtp',
            'connection' => 'redis',
            'stack' => 'notifications'
        ],

    ]

Preset: Example 1

Set a specific email address and use default queue:

php artisan mail:test --preset=example1

// php artisan mail:test preset1@example.com --queue

Preset: Example 2

Use the log mail driver and emails queue

php artisan mail:test --preset=example2

// php artisan mail:test --driver=log --stack=emails

Preset: Example 3

Use the log mail driver and emails queue

php artisan mail:test --preset=example3

// php artisan mail:test preset3@example.com --driver=smtp --connection=redis --stack=notifications

Alternatives

This is a simple package designed to quickly trigger an email to check your configuration.

If you want to check what an email looks like in the browser use the Laravel documentation to render mailables (available since Laravel 5.5).

If you need a package to send a mailable using fake data try using Spatie's laravel-mailable-test package.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

About

Quickly send test emails using commands in Laravel applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published