【问题标题】:send mail using resque-mailer -RAILS 3使用 resque-mailer -RAILS 3 发送邮件
【发布时间】:2014-02-09 09:33:09
【问题描述】:

我的应用程序在开发中在后台发送邮件,但最近我安装了 redis 和 resque 以使用 resque 和 resque-mailer,现在没有任何工作。每次我收到消息 RuntimeError Invalid delivery method :resque。我一直在努力弄清楚出了什么问题,因为之前我只是在 user_mailer.rb 中包含了 resque-mailer,仅此而已,我的邮件正在运行,但现在我不知道我做错了什么。下面是我使用 Railscasts for resque 安装 REDIS 后的相关文件。我用谷歌搜索了很多找到但是很多时候我遇到了猴子修补设计,但我认为我不需要这样做,因为我的邮件工作正常而不必担心设计。使用 ruby 1.9.3rails 3.2 我在尝试使用 sidekiq 时遇到同样的错误 :(

我的宝石文件。

gem 'resque','1.19.0' ,:require => "resque/server"
gem 'resque_mailer'

我的 user_mailer.rb

class UserMailer < ActionMailer::Base
  include Resque::Mailer
  default from: "support@mywebsite.com"


def logged_in(user.id)
  Rails.logger.info 'sending mail----------registeration mail----------'
  @user=User.find(user_id)
  p @user
  ###line number 19 is below
  mail(:to => @user.email, :subject => " Hi #{@user.username},You logged-in just now ")
end

app/controllers/users/devise/sessions_controller.rb

##enqueue the mailer using resque and send mail asynchronously
###this was working earlier but now its not so i made use of railscasts above to use redis
###UserMailer.logged_in(resource.id).deliver
@user_id=resource.id
Resque.enqueue(UserMailerWorker,@user_id)

现在我使用 Railscasts 和邮件所做的更改没有发送上述错误

我的工人

class UserMailerWorker
  @queue = :user_mailer_job_queue
  def self.perform(user_id)
    p 'usermailer worker sending logged in mail----'
    p user_id
    UserMailer.logged_in(user_id).deliver
  end
end

在 resque-web UI 中看到的回溯错误---

     localhost.localdomain:8119 on mailer at just now
    Retry or Remove
Class
    UserMailer
Arguments

    "logged_in"
    7

Exception
    RuntimeError
Error
    Invalid delivery method :resque

    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionmailer-3.2.0/lib/action_mailer/delivery_methods.rb:71:in `wrap_delivery_behavior'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionmailer-3.2.0/lib/action_mailer/delivery_methods.rb:83:in `wrap_delivery_behavior!'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionmailer-3.2.0/lib/action_mailer/base.rb:628:in `mail'
    /mnt/hgfs/latest-master/latest/app/mailers/user_mailer.rb:19:in `logged_in'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionpack-3.2.0/lib/abstract_controller/base.rb:167:in `process_action'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionpack-3.2.0/lib/abstract_controller/base.rb:121:in `process'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionpack-3.2.0/lib/abstract_controller/rendering.rb:45:in `process'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionmailer-3.2.0/lib/action_mailer/base.rb:456:in `process'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/actionmailer-3.2.0/lib/action_mailer/base.rb:451:in `initialize'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:48:in `new'
    /usr/local/rvm/gems/ruby-1.9.3-head@latest/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:48:in `perform'

【问题讨论】:

  • 能否提供错误的回溯
  • 添加了来自 resque web @Viren 的错误回溯

标签: ruby-on-rails ruby-on-rails-3 devise actionmailer resque


【解决方案1】:

在删除和重置我的应用程序之后...我开始知道为什么我会收到此错误。它是因为在使用 redis-server 和 @ 启动 redis 之后我没有开始 resque 工作以及 redis.so 987654323@ 使用bundle exec rake resque:work QUEUE='*'...我的异步邮件只需包含include Resque::Mailer 就可以毫无问题地开始工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-15
    • 1970-01-01
    • 2011-07-14
    • 2013-05-21
    • 2015-08-23
    • 2012-07-25
    • 1970-01-01
    • 2015-01-07
    相关资源
    最近更新 更多