【发布时间】:2016-01-12 22:20:36
【问题描述】:
我正在将应用程序升级到 Rails 4.2,以便我们可以利用 ActionMailer 的 deliver_later 方法。一切都在开发中运行良好。当我使用capistrano-sidekiq gem 部署到我们的登台服务器时,似乎没有发送电子邮件。根据此日志,该作业似乎已排队并正确执行。
服务器是 Ubuntu 14.04,通过 apt-get 安装了 redis。
[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 51ddade2-4689-40fd-aeda-7e94f7260e43) to Sidekiq(mailers) with arguments:
"ApplicationMailer", "admin_message", "deliver_now", "Broken Link", "Testing an email from staging."
[ActiveJob] [ActionMailer::DeliveryJob] [51ddade2-4689-40fd-aeda-7e94f7260e43] Performing ActionMailer::DeliveryJob from Sidekiq(mailers)
with arguments: "ApplicationMailer", "admin_message", "deliver_now", "Broken Link", "Testing an email from staging."
[ActiveJob] [ActionMailer::DeliveryJob] [51ddade2-4689-40fd-aeda-7e94f7260e43] Rendered application_mailer/admin_message.html.erb within layouts/mailer (1.9ms)
[ActiveJob] [ActionMailer::DeliveryJob] [51ddade2-4689-40fd-aeda-7e94f7260e43] Rendered layouts/mailer.html.erb (8.8ms)
[ActiveJob] [ActionMailer::DeliveryJob] [51ddade2-4689-40fd-aeda-7e94f7260e43] Rendered application_mailer/admin_message.text.erb within layouts/mailer (0.8ms)
[ActiveJob] [ActionMailer::DeliveryJob] [51ddade2-4689-40fd-aeda-7e94f7260e43] Rendered layouts/mailer.text.erb (3.6ms)
[ActiveJob] [ActionMailer::DeliveryJob] [51ddade2-4689-40fd-aeda-7e94f7260e43]
Sent mail to email-testing@loamstudios.com (216.8ms)
[ActiveJob] [ActionMailer::DeliveryJob] [51ddade2-4689-40fd-aeda-7e94f7260e43] Performed ActionMailer::DeliveryJob from Sidekiq(mailers) in 796.8ms
我检查了sidekiq是否使用ps aux | [sS]idekiq运行并且有一个条目:
deploy 15104 0.4 7.4 972692 152452 ? Sl 10:07 0:03 sidekiq 3.5.1 sustainabilityassessment_staging [0 of 25 busy]
我还确保邮件队列存在,set :sidekiq_queue, ["default", "mailers"] 在我的deploy.rb 中。
我的邮寄方式:
def admin_message(subject, message)
@message = message
mail(to: "<address>", subject: subject)
end
知道发生了什么或接下来我可以解决什么问题吗?
编辑:
做了一些更多的挖掘。我在appname/current 中使用RAILS_ENV=staging bundle exec sidekiq -q mailers -q default 开始sidekiq 并尝试再次发送电子邮件。这次发送的电子邮件,因此 capistrano-sidekiq gem 启动 sidekiq 的方式似乎有问题。
编辑: 设置 sidekiq 的监控应用程序,看看我是否可以学到任何新东西。似乎正在处理作业,没有问题。仍然没有收到电子邮件...
编辑:在config/environments/staging.rb 中发现了一个额外的config.action_mailer.raise_delivery_errors = false,它阻止我看到我的错误。我现在可以看到电子邮件被拒绝了:
Net::SMTPServerBusy: 454 4.7.1 <email address>: Relay access denied
编辑:还有一条信息,在同一个邮件程序上调用deliver_now。调用deliver_later 会导致电子邮件被拒绝。这让我认为该应用程序的 SMTP 设置正在运行。 deliver_later 调用中发生了一些事情,以阻止发送电子邮件。
【问题讨论】:
-
确保你的 Rails 配置中有
config.action_mailer.raise_delivery_errors = true。如果 ActionMailer 遇到错误,这将帮助您进行故障排除。 -
谢谢。添加了行。经测试。没有这样的运气。相同的日志条目。
-
使用
deliver_now时邮件是否发送成功?这将有助于缩小是配置问题还是 sidekiq 问题。 -
deliver_now工作。 -
您介意发布您的邮件方法的内容吗?我注意到使用 ActiveJob 会导致mailer methods to be executed twice。您的邮件方法在第二次执行时是否有可能表现不同?
标签: ruby-on-rails capistrano sidekiq