php - Laravel:带有队列的 Mailgun 动态发送域
问题描述
我需要更改从 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 不喜欢我的登录详细信息。
当我通过 Mail 门面发送电子邮件时,它可以工作,所以我的登录名是正确的。
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'),
是什么赋予了?
解决方案
如果您在 MAILGUN 上的 2 个域具有相同的密钥
$transport = (new TransportManager(app()))->driver('mailgun');
$transport->setDomain('yourdomain.com');
FacadeMail::setSwiftMailer(new Swift_Mailer($transport));
parent::send($mailer);
您可以在发送邮件之前将其放入。它也适用于队列
推荐阅读
- android - Recyclerview没有滚动嵌套滚动视图内的所有列表元素
- c++ - 用于将 shared_ptr 向量填充到基础和派生对象的函数模板
- php - 使用 queue:work 有问题吗?
- python - 不能将 Postgres 的 ARRAY 与 SQLAlchemy 一起使用
- c - 如何在 C 中创建结构的“对象”
- docker - 如何在 K8S 中保持没有入口点的 docker pod 运行?
- c# - 当我使用 (C#) 打开 excel 时,我无法使用来自外部插件(例如Bloomberg)的公式
- android - Android - MediaPlayer 未在 Android 9 设备上播放 SHOUTcast 流 URL
- python - 如何在 cayley graph db 中加载 json api
- web-hosting - 如何在虚拟主机中使用本地系统作为文件管理器