jsoma/mailerqueue

The Async mailer for the Yii framework

dev-master 2017-11-29 15:35 UTC

This package is not auto-updated.

Last update: 2024-05-12 02:20:42 UTC


README

yii2 redis async mailer

基于 Redis的邮件异步发送工具

1.config.php

'aliases' => [ '@jsoma/mailer'=>'@vendor/jsoma/mailerqueue/src' ],

'components' => [ ... 'redis' => [ 'class' => 'yii\redis\Connection', 'hostname' => 'localhost', // ip/127.0.0.1 'port' => 6379, 'database' => 0, ],

   ...

    'mailer' => [
        //redis 发送邮件
         'class' => 'jsoma\mailer\MailerQueue',
         'db' => '1', // redis select 1
         'key' => 'mails', // redis key
        'useFileTransport' => false,
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.163.com',
            'username' => 'xxx@163.com',
            'password' => 'xxx',
            'port' => '465',
            'encryption' => 'ssl',
        ],
    ], 
],
  1. mail to redis

    $mailer = Yii::$app->mailer->compose($template, $param=[]);//邮件体 $mailer->setFrom('xxx@163.com'); //发件人 $mailer->setTo('xxx@xxx.com'); // 收件人 $mailer->setSubject('xxx'); // 邮件标题 //if ($mailer->send()) { // if ($mailer->queue()) { // redis 发送 return true; }else{ return false; }

  2. Send mail by redis ( linux crontab 定时脚本)

    $mailer = new \jsoma\mailer\MailerQueue(); $mailer->process();