遅延ジョブジェムを使用していて、遅延ジョブでメールを送信しようとしています。
しかし、私はそれを行うことができませんでした、遅延したジョブログは常に次のように述べています:{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