Search code examples
ruby-on-railsactionmailerdelayed-job

Getting 'Use MyMailer.delay.mailer_action(args) to delay sending of emails.' error


I am getting an odd error: 'Use MyMailer.delay.mailer_action(args) to delay sending of emails.' but I can seem to find out where does it come from:

app/mailers/user_notifier.rb

class UserNotifier < ActionMailer::Base
  default from: "[email protected]"

  def signup_email(user)
    @user = user
    mail(to: @user.email, subject: t("mailer.signup.subject"))
  end

  ...
end

In Console, the non-delayed one works: UserNotifier.signup_email(user).deliver

but when adding delay, error occurs:

UserNotifier.signup_email(user).delay.deliver
  Rendered user_notifier/signup_email.html.erb (0.7ms)
RuntimeError: Use MyMailer.delay.mailer_action(args) to delay sending of emails.
    from /Users/quindici/.rvm/gems/ruby-2.1.2/gems/delayed_job-4.0.6/lib/delayed/performable_mailer.rb:20:in `delay'
    from (irb):6
    from /Users/quindici/.rvm/gems/ruby-2.1.2/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
    from /Users/quindici/.rvm/gems/ruby-2.1.2/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
    from /Users/quindici/.rvm/gems/ruby-2.1.2/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

It used to work but was broken sometimes ago. Still didn't get my head around it. Any idea would be much appreciated! Thank you.


Solution

  • I think you have it backwards:

    UserNotifier.signup_email(user).delay.deliver
    

    should be

    UserNotifier.delay.signup_email(user)