如何在我的电子邮件邮件中更改此代码,以便当current_user从应用程序发出电子邮件时,收件人会收到该邮件:from => current_user.email。
目前它来自“notification@example.com”,但我希望动态更改这是否可能,而不会导致电子邮件进入垃圾邮件?
class EmailMailer < ActionMailer::Base
default :from => "notification@example.com"
def email_listing(user, listing, email)
@user = user
@listing = listing
@email = email
@url = "www.example.com"
mail(:to => @email.email, :subject => @user.name)
end
end
答案 0 :(得分:5)
您只需传递from选项即可从地址添加自定义,并将回复地址的reply_to选项传递给mail方法,例如
def email_listing(user, listing, email)
@user = user
@listing = listing
@email = email
@url = "www.example.com"
mail(:to => @email.email, :subject => @user.name, from: 'notification@example.com', reply_to: @user.email)
end