tim*_*son 9 php smtp swiftmailer laravel laravel-forge
我们的电子邮件无法使用Redis Queue使用Laravel发送.
触发错误的代码是: ->onQueue('emails')
$job = (new SendNewEmail($sender, $recipients))->onQueue('emails');
$job_result = $this->dispatch($job);
Run Code Online (Sandbox Code Playgroud)
结合这项工作:
use InteractsWithQueue;
Run Code Online (Sandbox Code Playgroud)
我们的错误信息是:
Feb 09 17:15:57 laravel: message repeated 7947 times: [ production.ERROR: exception 'Swift_TransportException' with message 'Expected response code 354 but got code "550", with message "550 5.7.0 Requested action not taken: too many emails per second "' in /home/laravel/app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:383 Stack trace: #0 /home/laravel/app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(281):
Run Code Online (Sandbox Code Playgroud)
我们的错误只发生在使用Sendgrid而不是Mailtrap,这会欺骗电子邮件发送.我和Sendgrid谈过,电子邮件从未触及他们的服务器,当我的错误发生时,他们的服务完全处于活动状态.所以,错误似乎在我的最后.
有什么想法吗?
仅供调试!
如果您不希望收到超过 5 封电子邮件并且没有更改mailtrap的选项,请尝试:
foreach ($emails as $email) {
...
Mail::send(... $email);
if(env('MAIL_HOST', false) == 'smtp.mailtrap.io'){
sleep(1); //use usleep(500000) for half a second or less
}
}
Run Code Online (Sandbox Code Playgroud)
使用sleep()是一种非常糟糕的做法。理论上,这段代码应该只在测试环境或调试模式下执行。
我终于弄清楚了如何设置整个Laravel应用程序以基于配置限制邮件。
在boot()功能中AppServiceProvider,
$throttleRate = config('mail.throttleToMessagesPerMin');
if ($throttleRate) {
$throttlerPlugin = new \Swift_Plugins_ThrottlerPlugin($throttleRate, \Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE);
Mail::getSwiftMailer()->registerPlugin($throttlerPlugin);
}
Run Code Online (Sandbox Code Playgroud)
在中config/mail.php,添加以下行:
'throttleToMessagesPerMin' => env('MAIL_THROTTLE_TO_MESSAGES_PER_MIN', null), //https://mailtrap.io has a rate limit of 2 emails/sec per inbox, but consider being even more conservative.
Run Code Online (Sandbox Code Playgroud)
在.env文件中,添加如下一行:
MAIL_THROTTLE_TO_MESSAGES_PER_MIN=50
Run Code Online (Sandbox Code Playgroud)
唯一的问题是,如果,它似乎不会影响通过该later()函数发送的邮件QUEUE_DRIVER=sync。
| 归档时间: |
|
| 查看次数: |
13349 次 |
| 最近记录: |