izumi-kun/yii2-spoolmailer

Implements email queue using SwiftMailer spool transport and yii2-swiftmailer extension

Installs: 3 836

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 3

Forks: 1

Open Issues: 0

Type:yii2-extension

0.5.0 2017-11-30 19:42 UTC

This package is auto-updated.

Last update: 2024-11-15 05:53:23 UTC


README

Implements email queue using SwiftMailer spool transport and yii2-swiftmailer extension.

It supported queues based on built-in SwiftMailer spools or Yii2 Queue Extension.

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Code Coverage

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist izumi-kun/yii2-spoolmailer

or add

"izumi-kun/yii2-spoolmailer": "~1.0.0"

to the require section of your composer.json.

Basic Usage

This way uses built-in SwiftMailer spools: FileSpool (default) or MemorySpool.

Add the following code in your application configuration (both web and console):

return [
    //....
    'components' => [
        //....
        'mailer' => [
            'class' => izumi\spoolmailer\Mailer::class,
        ],
    ],
];

Add the following code in your console configuration:

return [
    //....
    'controllerMap' => [
        'mail' => izumi\spoolmailer\MailController::class,
    ],
];

You can then add an email in queue as follows:

Yii::$app->mailer->compose('contact/html')
     ->setFrom('from@domain.com')
     ->setTo($form->email)
     ->setSubject($form->subject)
     ->queue();

Process email queue by follow console command:

./yii mail/flush

CRON job:

* * * * * php /var/www/yii-app/yii mail/flush >/dev/null 2>&1

Advanced Usage

This way requires Yii2 Queue Extension in your application.

Add the following code in your application configuration (both web and console):

return [
    //....
    'components' => [
        //....
        'mailer' => [
            'class' => izumi\spoolmailer\Mailer::class,
            'spoolMailer' => [
                'class' => izumi\spoolmailer\spools\QueueSpool::class,
                'queue' => 'queue', // the application component ID of the queue object
            ],
        ],
    ],
];

For more details see the Yii2 Queue Guide.

License

BSD-3-Clause