简体   繁体   中英

send mail using resque-mailer -RAILS 3

My application was sending mails in background in development but recently i installed redis and resque to use resque along with resque-mailer and now nothing is working.Everytime i get a message RuntimeError Invalid delivery method :resque .I have been trying hard to figure out whats wrong because earlier i just included resque-mailer in user_mailer.rb and thats it,my mails were running but now i dont know what wrong i did.below are my relevant file AFTER INSTALLING REDIS using Railscasts for resque .I googled alot to find but many times i came across monkey patching devise but i dont think i need to do that as my mailers were working fine without worrying about devise.Using ruby 1.9.3 and rails 3.2 im getting same error when tried with sidekiq :(

my gemfile.

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

my 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)

now the changes that i did using Railscasts and mail is not sending giving above error

my worker

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

backtrace error as seen in 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'

拆除和重置我的应用程序后,好...我才知道为什么我得到这个error.its因为我不是开始启动后的resque工作以及redis.so redis使用redis-serverresque使用bundle exec rake resque:work QUEUE='*' ...仅包含include Resque::Mailer我的异步邮件就开始正常工作而没有任何问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM