Reputation: 1117
How can I change this code in my email mailer so that when current_user sends out an email from the application it is received by the recipient :from => current_user.email.
Currently it is from "[email protected]" but I would like this to change dynamically and Is this possible without resulting in emails going into junk?
class EmailMailer < ActionMailer::Base
default :from => "[email protected]"
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
Upvotes: 3
Views: 2147
Reputation: 76
You can just pass the from option to add a custom from address, and pass the reply_to option for a reply address into the mail method, like
def email_listing(user, listing, email)
@user = user
@listing = listing
@email = email
@url = "www.example.com"
mail(:to => @email.email, :subject => @user.name, from: '[email protected]', reply_to: @user.email)
end
Upvotes: 6