2017 © Pedro Peláez
 

yii2-extension yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

image

macklus/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  • Friday, September 1, 2017
  • by macklus
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 39 Forks
  • 0 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist dantart/yii2-mailqueue "*"

or add, (*4)

"dantart/yii2-mailqueue": "*"

to the require section of your composer.json file., (*5)

Configuration

Once the extension is installed, add following code to your application configuration :, (*6)

return [
    //....
    'components' => [
        'mailqueue' => [
            'class' => 'dantart\mailqueue\MailQueue',
            'table' => '{{%mail_queue}}',
            'mailsPerRound' => 10,
            'maxAttempts' => 3,
        ],
    ],
];

Following properties are available for customizing the mail queue behavior., (*7)

  • table: Name of the database table to store emails added to the queue.
  • mailsPerRound: Number of emails to send at a time.
  • maxAttempts: Maximum number of sending attempts per email.

Updating database schema

Apply the database migration to create the table required to store the mail queue messages. To do this, add following code to /config/console.php:, (*8)

return [
    //....
    'components' => [
        'mailqueue' => [
            'class' => 'dantart\mailqueue\MailQueue',
            'table' => '{{%mail_queue}}',
        ],
    ],
];

then run yii migrate command in command line:, (*9)

php yii migrate/up --migrationPath=@vendor/dantart/yii2-mailqueue/migrations/

Processing the mail queue

Now calling process() on Yii::$app->mailqueue will process the message queue and send out the emails. In one of your controller actions:, (*10)


public function actionSend() { Yii::$app->mailqueue->process(); }

Most preferably this could be a console command (eg: mail/send) which can be triggered by a CRON job., (*11)

Setting the CRON job

Set a CRON job to run console command:, (*12)


*/10 * * * * php /var/www/html/myapp/yii mailqueue/process

Usage

You can then send an email to the queue as follows:, (*13)

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

While dantart\mailqueue\MailQueue extends from yii\swiftmailer\Mailer, you can replace it with this extension by adding yii2-swiftmailer configuations directly to mailqueue configurations as follows:, (*14)

return [
    //....
    'components' => [
        'mailqueue' => [
            'class' => 'dantart\mailqueue\MailQueue',
            'table' => '{{%mail_queue}}',
            'mailsPerRound' => 10,
            'maxAttempts' => 3,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'localhost',
                'username' => 'username',
                'password' => 'password',
                'port' => '587',
                'encryption' => 'tls',
            ],
        ],
    ],
];

And use following code for directly sending emails as you ususally do with yii2-swiftmailer:, (*15)

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

License

MIT, (*16)

The Versions

01/09 2017

dev-master

9999999-dev https://github.com/dantart/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

03/04 2017

v0.0.15

0.0.15.0 https://github.com/dantart/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

20/03 2017

0.0.14

0.0.14.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

11/03 2017

0.0.13

0.0.13.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

01/12 2016

0.0.12

0.0.12.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

14/11 2016

0.0.11

0.0.11.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

14/11 2016

0.0.10

0.0.10.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

12/11 2016

0.0.9

0.0.9.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

20/09 2016

0.0.8

0.0.8.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

22/06 2016

0.0.7

0.0.7.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

23/05 2016

0.0.6

0.0.6.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

22/05 2016

0.0.5

0.0.5.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

14/04 2016

0.0.4

0.0.4.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

01/02 2016

0.0.3

0.0.3.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

19/01 2016

0.0.2

0.0.2.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer

09/10 2015

0.0.1

0.0.1.0 https://github.com/nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

component email extension yii2 swiftmailer queue yii2-swiftmailer