Sidekiq和Rails 4 Actionmailer从不发送电子邮件 [英] Sidekiq and rails 4 actionmailer never delivers emails

查看:107
本文介绍了Sidekiq和Rails 4 Actionmailer从不发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Rails 4应用程序中设置了sidekiq,用于发送电子邮件和处理后台作业。我还设计了我正在使用devise_async和典型的联系表单电子邮件发送器的设备。我正在使用gmail来发送电子邮件。

I've setup sidekiq in a rails 4 application for sending emails and processing background jobs. I have also devise which I am using devise_async and a typical contact form emailer. I am using gmail for sending emails.

如果我删除了sidekiq,它通常会通过gmail(设计和联系方式)发送电子邮件,但是当我启用它时,它将不起作用(既devise_async也没有联系表格)。 Sidekiq显示后台作业成功启动和完成(我也通过sinatra应用程序看到了这些作业已被处理),但是电子邮件从未发送过。

If I remove sidekiq, it sends the emails normally through gmail (both devise and contact form) but when I am enabling it, it doesn't work (neither devise_async neither contact form). Sidekiq shows that the background jobs starts and finishes successfully (I also see them through the sinatra app that it's been processed) but the email never been delivered.

在开发中,控制台显示发送的电子邮件(都是通过devise_async以及从联系人表单发送的,因为它们已成功通过sidekiq处理)。

In development, the console shows that the emails sent (both with devise_async and from contact form, as they are processed with sidekiq successfully).

我已经尝试过的内容:


  • 我已经添加了sidekiq的rails4的github分支(我也尝试过使用master)

  • 我已更新并检查redis版本是否大于
    2.4(为2.6.14)

  • 我正在使用 bundle exec sidekiq

  • I've added the github branch for rails4 of sidekiq (I've also tried the master)
  • I've updated and check redis version to be greater than 2.4 (it's 2.6.14)
  • I am running sidekiq with bundle exec sidekiq

,但没有任何效果。我正在使用ruby 2.0.0-p247。

but nothing worked. I am using ruby 2.0.0-p247.

我还在此应用程序中使用sidekiq设置了图像处理,并且在开发和生产中均能完美运行。

I have also setup image processing with sidekiq in this app and works perfectly both in development and in production.

我没有做任何花哨的事情,但是我添加了完成代码:

I am not doing anything fancy but I am adding the code for completion:

我的邮件代码:

  def send_message
   @message = Message.new(message_params)
   if @message.save
     ContactMailer.delay.contact_form(@message.id)
   end
 end

我的邮件:

  def contact_form(message_id)
    message = Message.where(id: message_id).first
    @email = message.email
    @message = message.text
    mail(to: "myemail@gmail.com", subject: "Message from contact form")
  end

和我的生产配置(无需sidekiq即可使用):

and my configuration for production (which it works without sidekiq):

  config.action_mailer.delivery_method = :smtp
  ActionMailer::Base.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :domain               => "gmail.com",
    :authentication       => "plain",
    :enable_starttls_auto => true,
    :user_name            => "myusername",
    :password             => "mypassword"
  }
  config.action_mailer.default_url_options = { :host => "mydomain.com" }

这是典型的sidekiq队列:

And here a typical sidekiq queue:

    /home/john/.rvm/gems/ruby-2.0.0-p247@cluey/bundler/gems/sidekiq-4ed6eba8aff1/lib/sidekiq/rails.rb:14: warning: toplevel constant Queue referenced by Sidekiq::Client::Queue
    2013-07-19T09:47:56Z 20112 TID-1a5mkc INFO: Booting Sidekiq 2.5.2 with Redis at redis://localhost:6379/0
    2013-07-19T09:47:56Z 20112 TID-1a5mkc INFO: Running in ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
    2013-07-19T09:47:56Z 20112 TID-1a5mkc INFO: See LICENSE and the LGPL-3.0 for licensing details.
    2013-07-19T09:47:56Z 20112 TID-1a5mkc INFO: Starting processing, hit Ctrl-C to stop
    2013-07-19T09:48:11Z 20112 TID-1u2z02 Devise::Async::Backend::Sidekiq JID-4a7e66a14deab112191e4b49 INFO: start
    2013-07-19T09:48:12Z 20112 TID-1u2z02 Devise::Async::Backend::Sidekiq JID-4a7e66a14deab112191e4b49 INFO: done: 1.214 sec
    2013-07-19T09:48:50Z 20112 TID-1u2z02 Devise::Async::Backend::Sidekiq JID-32191822b789f5b6896a5353 INFO: start
2013-07-19T09:48:51Z 20112 TID-1u2z02 Devise::Async::Backend::Sidekiq JID-32191822b789f5b6896a5353 INFO: done: 0.143 sec
2013-07-19T09:49:29Z 20112 TID-1u2z02 Sidekiq::Extensions::DelayedMailer JID-c1911e0c4b72295dc067d57f INFO: start
2013-07-19T09:49:29Z 20112 TID-1u2z02 Sidekiq::Extensions::DelayedMailer JID-c1911e0c4b72295dc067d57f INFO: done: 0.152 sec

我认为这与actionmailer和sidekiq有关,但我不知道如何调试,一切似乎都可以正常工作,但电子邮件从不

I think it has to do with actionmailer and sidekiq but I don't know how to debug, everything seems to work but the emails never delivered.

推荐答案

我发现了,您必须像这样运行sidekiq:

I found it, you have to run sidekiq like this:

RAILS_ENV=production bundle exec sidekiq -D

投入生产与资产预编译是相同的问题。

to run in production. It's the same issue as the assets precompile.

这篇关于Sidekiq和Rails 4 Actionmailer从不发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆