简体   繁体   English

Rails:延迟作业 - >发送异步邮件时不从“字段”中取出

[英]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. 我正在运行2.1.1,Rails 3,并且有一个heckuva时间让delayed_job宝石工作。 If I strip out handle_asynchronously on a mailer, everything works fine...but if I put it back in, I get: 如果我在邮件程序上删除handle_asynchronously,一切正常......但如果我把它重新插入,我得到:

undefined method `name' for nil:NilClass (where 'name' comes from @contact.name ...which works fine when handle_asynchronously is disabled). nil的未定义方法`name':NilClass(其中'name'来自@ contact.name ...当handle_asynchronously被禁用时,它工作正常)。

If I strip out all the @contact template info, I get: 如果我删除所有@contact模板信息,我得到:

"A sender (Return-Path, Sender or From) required to send a message"? “发送邮件所需的发件人(Return-Path,Sender或From)”?

Is this me doing something wrong or some sorta bug? 这是我做错了什么或者某种错误吗? Relevant code below (my@email.here replaced with legit email address) 下面的相关代码(my@email.here替换为合法的电子邮件地址)

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@email.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... 你的错误说你在一个零对象上调用了名字,但我看不到你在哪里调用.name ...

Rails 3 Mailers 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. 由于邮件如何在Rails 3中实现,我们不得不做一些工作来使delayed_job工作。

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

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

Remove the .deliver method to make it work. 删除.deliver方法以使其工作。 It's not ideal, but it's the best we could do for now 它并不理想,但它是我们现在能做的最好的事情

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

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.. 但是我不知道它为什么会撞到这条线..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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