0

我正在尝试设置异步电子邮件发送。我正在使用延迟作业。没有 delay_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
4

1 回答 1

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

因此,在调用您的邮件方法时使用delaydeliver如下所示。

 YourMailer.delay.phrase_email(user, tweet, keyword, phrase) #With delay

 YourMailer.phrase_email(user, tweet, keyword, phrase).deliver  #Without delay

handle_asynchronously从 YourMailer 中删除。

此处的文档中明确提到了这一点。您不能handle_asynchronously与邮件一起使用。

于 2013-03-13T18:45:00.320 回答