开发者

Rails: Delayed Job --> Not picking up 'from' field when sending asynchronous mail

I'm running 2.1.1, Rails 3, and having a heckuva time getting the delayed_job gem working. If I strip out handle_asynchronously on a mailer, everything works fine...but if I put it back in, I get:

undefined method `name' for nil:NilClass (where 'name' comes from @contact.name ...which works fine when handle_asynchronously is disabled).

If I strip out all the @contact template info, I get:

"A sender (Return-Path, Sender or From) required to send a message"?

Is this me doing something wrong or some sorta bug? Relevant code below (my@email.here replaced with legit email address)

class ContactMailer < ActionMailer::Base
  default :from => "my@email.here"  

  def contact_mail(contact)
    @contact = contact
    mail(:to => ENV['MANAGER_EMAIL'], :subject => 'Delayed Job Test', :from => 'my@e开发者_开发问答mail.here', :content_type => 'text/plain')
  end

  handle_asynchronously :contact_mail, :run_at => Proc.new { 2.seconds.from_now }
end

Any suggestions very appreciated.


Try calling the method with the actual email address:

def contact_mail(contact_email)
  mail(:to => ENV['MANAGER_EMAIL'], :subject => 'Delayed Job Test', :from => contact_email, :content_type => 'text/plain')
end

That's the only thing I can think of which might help without seeing your actual code. Your error says you're calling name on a nil object, but I can't see anywhere where you're calling .name...


I had the same problem and solved it by removing this line:

default :from => "my@email.here" 

But I don't know why it crashed with this line..


Rails 3 Mailers

Due to how mailers are implemented in Rails 3, we had to do a little work around to get delayed_job to work.

# without delayed_job
Notifier.signup(@user).deliver

# with delayed_job
Notifier.delay.signup(@user)

Remove the .deliver method to make it work. It’s not ideal, but it’s the best we could do for now

https://github.com/collectiveidea/delayed_job#rails-3-mailers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜