我需要在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'),
有什么作用?
答案 0 :(得分:0)
如果MAILGUN上的两个域具有相同的密钥
$transport = (new TransportManager(app()))->driver('mailgun');
$transport->setDomain('yourdomain.com');
FacadeMail::setSwiftMailer(new Swift_Mailer($transport));
parent::send($mailer);
您可以在发送邮件之前先放置它。 它也可以在队列中使用