是否可以在 laravel 可邮寄邮件中设置邮件程序?

Is it possible to set the mailer within a laravel mailable?

我有一个可邮寄的邮件,我希望它始终使用特定的邮件程序。目前,我这样发送邮件:

Mail::mailer('smtp2')->to($recipient)->send(new AuthTokenMail());

我想做的是在 mailable 中设置邮件程序,就像我设置队列一样,如下所示:

class AuthTokenMail extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    public function __construct(int $code)
    {
        $this->onQueue('email2');
        $this->mailer('smtp2');   // doesn't work!
    }

    ...

为了能够使用您需要在 mail.php 配置文件中设置的特定邮件详细信息。像这样:

'mailers' => [
            'smtp' => [
                'transport' => 'smtp',
                'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
                'port' => env('MAIL_PORT', 587),
                'encryption' => env('MAIL_ENCRYPTION', 'tls'),
                'username' => env('MAIL_USERNAME'),
                'password' => env('MAIL_PASSWORD'),
                'timeout' => null,
                'auth_mode' => null,
            ],
            'smtp2' => [
                'transport' => 'smtp',
                'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
                'port' => env('MAIL_PORT', 587),
                'encryption' => env('MAIL_ENCRYPTION', 'tls'),
                'username' => env('MAIL_USERNAME'),
                'password' => env('MAIL_PASSWORD'),
                'timeout' => null,
                'auth_mode' => null,
            ],
        ...
        ...
        ...
    ];