|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) |
| 6 | + * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org/) |
| 7 | + * |
| 8 | + * Licensed under The MIT License |
| 9 | + * For full copyright and license information, please see the LICENSE.txt |
| 10 | + * Redistributions of files must retain the above copyright notice. |
| 11 | + * |
| 12 | + * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org/) |
| 13 | + * @link https://cakephp.org CakePHP(tm) Project |
| 14 | + * @since 0.1.9 |
| 15 | + * @license https://opensource.org/licenses/MIT MIT License |
| 16 | + */ |
| 17 | +namespace Cake\Queue\Mailer\Transport; |
| 18 | + |
| 19 | +use Cake\Mailer\Message; |
| 20 | +use Cake\Mailer\Transport\MailTransport; |
| 21 | +use Cake\Queue\Job\SendMailJob; |
| 22 | +use Cake\Queue\QueueManager; |
| 23 | + |
| 24 | +class QueueTransport extends \Cake\Mailer\AbstractTransport |
| 25 | +{ |
| 26 | + /** |
| 27 | + * Default config for this class |
| 28 | + * |
| 29 | + * @var array<string, mixed> |
| 30 | + */ |
| 31 | + protected $_defaultConfig = [ |
| 32 | + 'options' => [], |
| 33 | + 'transport' => MailTransport::class, |
| 34 | + ]; |
| 35 | + |
| 36 | + /** |
| 37 | + * @inheritDoc |
| 38 | + */ |
| 39 | + public function send(Message $message): array |
| 40 | + { |
| 41 | + QueueManager::push( |
| 42 | + [SendMailJob::class, 'execute'], |
| 43 | + [ |
| 44 | + 'transport' => $this->getConfig('transport'), |
| 45 | + 'config' => $this->getConfig(), |
| 46 | + 'emailMessage' => serialize($message), |
| 47 | + ], |
| 48 | + $this->getConfig('options') |
| 49 | + ); |
| 50 | + |
| 51 | + $headers = $message->getHeadersString( |
| 52 | + [ |
| 53 | + 'from', |
| 54 | + 'to', |
| 55 | + 'subject', |
| 56 | + 'sender', |
| 57 | + 'replyTo', |
| 58 | + 'readReceipt', |
| 59 | + 'returnPath', |
| 60 | + 'cc', |
| 61 | + 'bcc', |
| 62 | + ], |
| 63 | + ); |
| 64 | + |
| 65 | + return ['headers' => $headers, 'message' => 'Message has been enqueued']; |
| 66 | + } |
| 67 | +} |
0 commit comments