88

How can I define a reply-to address different than the :from one? Is that even possible?

Kara
  • 6,115
  • 16
  • 50
  • 57
empz
  • 11,509
  • 16
  • 65
  • 106

2 Answers2

156

Two ways:

class Notifications < ActionMailer::Base
  default :from     => 'your_app@your_domain.com',
          :reply_to => 'some_other_address@your_domain.com'
end

Or:

class Contacts < ActionMailer::Base
  def new_contact
    mail( :to       => 'somebody@some_domain.com',
          :from     => 'your_app@your_domain.com',
          :reply_to => 'someone_else@some_other_domain.com')
  end
end

Or you can mix the two approaches. I'm sure there are even more ways to do this.

dogenpunk
  • 4,332
  • 1
  • 21
  • 29
  • 4
    Silly boy, I've looked everywhere but the mail method definition: http://apidock.com/rails/ActionMailer/Base/mail Thank you! – empz May 05 '11 at 17:51
  • The official docs show this too: http://api.rubyonrails.org/classes/ActionMailer/Base.html#method-i-mail – user664833 May 24 '13 at 22:15
  • 1
    According to this: https://www.igvita.com/2007/07/21/sendmail-spam-filter-tricks-in-rails/ they should match, or your mail will get flagged by spam software. – Dan Barron Oct 09 '14 at 15:30
1

Solution for Rails 5.2 and possibly older/newer versions:

Amend the file:

config/environments/development.rb

With content:

Rails.application.configure do
  config.action_mailer.default_options = {
      reply_to:             'test@example.com'
  }
end

The reference:

https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration

laimison
  • 1,409
  • 3
  • 17
  • 39