3

如何在我的电子邮件邮件程序中更改此代码,以便当 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 
4

1 回答 1

6

您可以只传递 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
于 2013-05-09T00:41:40.077 回答