我正在尝试设置异步电子邮件发送。我正在使用delayed_job。 Withoud delayed_job一切正常,没有任何错误。但是当我补充说:
handle_asynchronously :mail_sending_method
我收到以下错误:
A sender (Return-Path, Sender or From) required to send a message
我使用ActionMailer发送邮件,特别是这样:
mail(:to => user.email, :from => "notifications@example.com", :subject => "Blah")
以下是方法:
def phrase_email(user, tweet, keyword, phrase)
@user = user
@tweet = tweet
@keyword = keyword
@phrase = phrase
mail(:to => user.email, :from => "notifications@example.com", :subject => "Weekapp Phrase Notification")
end
答案 0 :(得分:2)
延迟作业与Rails 3 Mailers
的工作方式不同。
class YourMailer < ActionMailer::Base
def phrase_email(user, tweet, keyword, phrase)
@user = user
@tweet = tweet
@keyword = keyword
@phrase = phrase
mail(:to => user.email, :from => "notifications@example.com", :subject => "Weekapp Phrase Notification")
end
end
因此,在调用您的邮件程序方法时,请使用delay
或deliver
,如下所示。
YourMailer.delay.phrase_email(user, tweet, keyword, phrase) #With delay
YourMailer.phrase_email(user, tweet, keyword, phrase).deliver #Without delay
从YourMailer中移除handle_asynchronously
。
文档here中明确提到了这一点。您不能将handle_asynchronously
与邮寄者一起使用。