定制 cbm/yii2-mailqueue 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cbm/yii2-mailqueue

最新稳定版本:0.1.0

Composer 安装命令:

composer require cbm/yii2-mailqueue

包简介

Message queue for emails extension for the Yii framework

README 文档

README

This extension provides an email solution via message queueing for Yii 2. It comes ready for RabbitMQ. For other MQs you can provide your own "mqMessageClass" (see below) as long as it implements the QueueMessageInterface. You need of course a message queue like RabbitMQ installed.

Be aware that this extension is stable but not ready for production yet.

Please submit issue reports and pull requests to https://github.com/chrisb88/yii2-mailqueue.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist cbm/yii2-mailqueue

or add

"cbm/yii2-mailqueue": "*"

to the require section of your composer.json.

Usage

Sample configuration:

return [
    //....
    'components' => [
        // This is the message queue mailer config, it substitutes the original mailer config
        'mailer' => [
            'class' => 'cbm\mailqueue\QueueMailer',
            'mqMessageClass' => 'cbm\mailqueue\RabbitMessage',
            'mqConfig' => [
                'host' => 'localhost',
                'port' => 5672,
                'user' => 'guest',
                'password' => 'guest',
                'queue' => 'email_task',
                'publishRoutingKey' => 'email_task',
            ],
        ],
        // You also need the original yii swift mailer but with a different name
        'emailMailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            //....
        ],
    ],
];

You can then send an email to the queue as follows (no change to the original implementation):

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

Don't forget to rename your original yii swift mailer to "emailMailer". It is still needed to really send the emails.

Get the email consumer running

Copy the file console/controller under your application console/controller (or where ever your console commands are) and run

yii email-task

The consumer will then listen to email messages and send them using the original yii swift mailer.

统计信息

  • 总下载量: 48
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-01