如何解决Lumen 电子邮件有时会因“Connection to tcp://smtp.mailgun.org:587 Timed Out”而失败,但未使用 Mailgun
我的系统包含两个内置于 Lumen(版本 6)的 API,一个创建邮件作业并将其发送到 SQS 队列,另一个从队列中读取并使用 Amazon SES 处理邮件。
大多数情况下,电子邮件都可以成功发送和接收,但是,有时我会在 Sentry 中收到以下错误(同时出现两个错误)
Swift_TransportException: Connection to tcp://smtp.mailgun.org:587 Timed Out
&
Swift_TransportException: Expected response code 250 but got code "550",with message "550 5.7.1 Relaying denied"
导致永远不会收到电子邮件。
奇怪的是我没有使用 Mailgun,所以我不确定为什么错误引用了 Mailgun。
我已确保 .env
文件中两个 API 的值都是正确的
MAIL_DRIVER=ses
MAIL_MAILER=ses
MAIL_HOST=XXX
MAIL_USERNAME=XXX
MAIL_PASSWORD=XXX
并已通过 PHP artisan tinker
和 config('mail')
检查是否已在实时服务器(ECS 容器)上正确加载配置
>>> config('mail')
=> [
"driver" => "ses","host" => "XXX","port" => 587,"from" => [
"address" => "hello@example.com","name" => "Example",],"encryption" => "tls","username" => "XXX","password" => "XXX","sendmail" => "/usr/sbin/sendmail -bs","markdown" => [
"theme" => "default","paths" => [
"/var/www/app/resources/views/vendor/mail","log_channel" => null,]
我也尝试过 PHP artisan cache:clear
,但是我无法运行 PHP artisan config:clear
,因为 Lumen 没有该命令。
有什么想法为什么某些电子邮件因上述错误而失败?或者我还能如何调试这个?
这是我的两个 API 的 config/mail.PHP
的内容
<?PHP
return [
/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP's "mail" function as drivers for the
| sending of e-mail. You may specify which one you're using throughout
| your application here. By default,Laravel is setup for SMTP mail.
|
| Supported: "smtp","sendmail","mailgun","ses",| "postmark","log","array"
|
*/
'driver' => env('MAIL_DRIVER','smtp'),/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/
'host' => env('MAIL_HOST','smtp.mailgun.org'),/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/
'port' => env('MAIL_PORT',587),/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here,you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS','hello@example.com'),'name' => env('MAIL_FROM_NAME','Example'),/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/
'encryption' => env('MAIL_ENCRYPTION','tls'),/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication,you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/
'username' => env('MAIL_USERNAME'),'password' => env('MAIL_PASSWORD'),/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails,we will need to kNow
| the path to where Sendmail lives on this server. A default path has
| been provided here,which will work well on most of your systems.
|
*/
'sendmail' => '/usr/sbin/sendmail -bs',/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering,you may configure your
| theme and component paths here,allowing you to customize the design
| of the emails. Or,you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default','paths' => [
resource_path('views/vendor/mail'),/*
|--------------------------------------------------------------------------
| Log Channel
|--------------------------------------------------------------------------
|
| If you are using the "log" driver,you may specify the logging channel
| if you prefer to keep mail messages separate from other log entries
| for simpler reading. Otherwise,the default channel will be used.
|
*/
'log_channel' => env('MAIL_LOG_CHANNEL'),];
解决方法
结果是 Laravel / Lumen 队列工作器在暂存时从 SQS 队列中拉取作业(暂存配置错误)
解决方案是为暂存创建一个单独的 SQS 队列,并更新 .env
以查看该队列
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。