Laravel:带队列的Mailgun动态发送域

问题描述 投票:0回答:1

我需要在Laravel发送的某些电子邮件上更改发送域。为此,我已经设置了排队的作业,并且in handle方法按如下所述配置Swift_SmtpTransport对象:Laravel Mail Queue: change transport on fly

public function handle(Mailer $mailer)
{
    $transport = new \Swift_SmtpTransport(config('mail.host'), config('mail.port'), config('mail.encryption'));

    $transport->setUsername(config('mail.username'));
    $transport->setPassword(config('mail.password'));
    $transport->setLocalDomain(env('MAILGUN_EMAIL_DOMAIN'));

    $smtp = new \Swift_Mailer($transport);

    $mailer->setSwiftMailer($smtp);

    $mailer->send('emails.email', ['data'], function ($m) {
        $m->setTo($this->to)
          ->setBody($this->email->emailResponse)
          ->setSubject(sprintf('%s [Ref: #%s]', $this->email->emailThread->subject, $this->email->emailThread->slug));
    });
}

由于某些原因,Mailgun不喜欢我的登录详细信息。

当我通过邮件外观发送电子邮件时,它可以正常工作,因此我的登录名是正确的。

Failed to authenticate on SMTP server with username "xxx" using 2 possible authenticators. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 but got code "535", with message "535 5.7.0 Mailgun is not loving your login or password
" in /home/vagrant/code/myapp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457

mail.php中,我有:

'username' => env('MAIL_USERNAME'),

'password' => env('MAIL_PASSWORD'),

什么给了?

php laravel swiftmailer mailgun
1个回答
0
投票

如果您对MAILGUN的2个域具有相同的密钥,则>

 $transport = (new TransportManager(app()))->driver('mailgun');
 $transport->setDomain('yourdomain.com');    
 FacadeMail::setSwiftMailer(new Swift_Mailer($transport));
 parent::send($mailer);

您可以在发送邮件之前先放置它。它也适用于队列]

© www.soinside.com 2019 - 2024. All rights reserved.