1

我正在使用延迟工作 gem 并尝试发送延迟工作的电子邮件。

但我没有这样做,延迟的作业日志总是指出:{A sender (Return-Path, Sender or From) required to send a message

另一方面,如果我不使用延迟工作,我可以成功发送电子邮件。

最奇怪的事!!!如果我使用延迟工作发送电子邮件

run at刚刚在数据库中创建的延迟作业记录的列与列相同created at

控制器代码:

def create
    @long_task = LongTask.new(params[:long_task])

    respond_to do |format|
      if @long_task.save
        # @long_task.set_delay_time(2)

        Notifier.delay.create_long_task
        # Notifier.create_long_task.deliver

        format.html { redirect_to @long_task, notice: 'Long task was successfully created.' }
        format.json { render json: @long_task, status: :created, location: @long_task }
      else
        format.html { render action: "new" }
        format.json { render json: @long_task.errors, status: :unprocessable_entity }
      end
    end
end

邮寄者:

class Notifier < ActionMailer::Base
  default from: "from@example.com"

  # Subject can be set in your I18n file at config/locales/en.yml
  # with the following lookup:
  #
  #   en.notifier.create_long_task.subject
  #
  def create_long_task
    #@greeting = "Hi"
    #@longTask ="delay setting"
    # @longTask = longTask

    mail to: "j-xxx@hotmail.com", :subject => 'Long Task Created'
  end

   handle_asynchronously :create_long_task, :run_at => Proc.new { 2.minutes.from_now }
end

电子邮件模板:

Notifier#create_long_task

You created a long task 
4

0 回答 0