Skip to content

stackkit/laravel-database-emails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b0a1e98 · Jul 24, 2018

History

53 Commits
Mar 31, 2018
Dec 22, 2017
Jul 24, 2018
Mar 31, 2018
Jun 29, 2017
Mar 31, 2018
Dec 22, 2017
Mar 18, 2018
Jun 28, 2017
Mar 22, 2018
Dec 22, 2017
Jun 28, 2017
Dec 22, 2017

Repository files navigation

Build Status Latest Stable Version License

Introduction

This is a package that stores and queues e-mails using a database table. Easily send e-mails using a cronjob and schedule e-mails that should be sent at a specific date and time.

Table Of Contents

Installation

First, require the package using composer.

composer require buildcode/laravel-database-emails

If you're running Laravel 5.5 or later you may skip this step. Add the service provider to your application.

Buildcode\LaravelDatabaseEmails\LaravelDatabaseEmailsServiceProvider::class,

Publish the configuration files.

php artisan vendor:publish --provider=Buildcode\\LaravelDatabaseEmails\\LaravelDatabaseEmailsServiceProvider

Create the database table required for this package.

php artisan migrate

Now add the e-mail cronjob to your scheduler.

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
     $schedule->command('email:send', ['--timeout' => 300])->everyMinute()->withoutOverlapping(5);
}

Using the above configuration, the email:send process will exit after 5 minutes (--timeout) and won't overlap if the process still runs after 5 minutes (withoutOverlapping)

Usage

Send an email

use Buildcode\LaravelDatabaseEmails\Email;

Email::compose()
    ->label('welcome')
    ->recipient('[email protected]')
    ->subject('This is a test')
    ->view('emails.welcome')
    ->variables([
        'name' => 'John Doe',
    ])
    ->send();

Specify multiple recipients

use Buildcode\LaravelDatabaseEmails\Email;

Buildcode\LaravelDatabaseEmails\Email::compose()
    ->recipient([
        '[email protected]',
        '[email protected]'
    ]);

CC and BCC

use Buildcode\LaravelDatabaseEmails\Email;

Email::compose()
    ->cc('[email protected]')
    ->cc(['[email protected]', '[email protected]'])
    ->bcc('[email protected]')
    ->bcc(['[email protected]', '[email protected]']);

Using mailables

You may also pass a mailable to the e-mail composer.

use Buildcode\LaravelDatabaseEmails\Email;

Email::compose()
    ->mailable(new OrderShipped())
    ->send();

Attachments

use Buildcode\LaravelDatabaseEmails\Email;

Email::compose()
    ->attach('/path/to/file');

Or for in-memory attachments:

use Buildcode\LaravelDatabaseEmails\Email;

Email::compose()
    ->attachData('<p>Your order has shipped!</p>', 'order.html');

Custom Sender

use Buildcode\LaravelDatabaseEmails\Email;

Email::compose()
    ->from('[email protected]', 'John Doe');

Scheduling

You may schedule an e-mail by calling later instead of send. You must provide a Carbon instance or a strtotime valid date.

use Buildcode\LaravelDatabaseEmails\Email;

Email::compose()
    ->later('+2 hours');

Resend failed e-mails

Resend all failed e-mails
php artisan email:resend
Resend a specific failed e-mail
php artisan email:resend 1

Encryption (Optional)

If you wish to encrypt your e-mails, please enable the encrypt option in the configuration file. This is disabled by default. Encryption and decryption will be handled by Laravel's built-in encryption mechanism. Please note that by encrypting the e-mail it takes more disk space.

Without encryption

7    bytes (label)
16   bytes (recipient)
20   bytes (subject)
48   bytes (view name)
116  bytes (variables)
1874 bytes (e-mail content)
4    bytes (attempts, sending, failed, encrypted)
57   bytes (created_at, updated_at, deleted_at)
... x 10.000 rows = ± 21.55 MB

With encryption the table size is ± 50.58 MB.

Test mode (Optional)

When enabled, all newly created e-mails will be sent to the specified test e-mail address. This is turned off by default.

E-mails to send per minute

To configure how many e-mails should be sent each command, please check the limit option. The default is 20 e-mails every command.

About

Store e-mails in the database and send them using a cronjob

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published