From 5c0d38f6749e91c9847f6a4d56264d83253b3539 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 27 Mar 2008 17:54:02 +0000 Subject: Fixed that a return-path header would be ignored (closes #7572) [joost] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9099 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionmailer/CHANGELOG | 2 ++ actionmailer/lib/action_mailer/base.rb | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index 89ddcc5ad7..15c9964d9b 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that a return-path header would be ignored #7572 [joost] + * Less verbose mail logging: just recipients for :info log level; the whole email for :debug only. #8000 [iaddict, Tarmo Tänav] * Updated TMail to version 1.2.1 [raasdnil] diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index ab3ca7f1be..56db84f17c 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -40,10 +40,14 @@ module ActionMailer #:nodoc: # * content_type - Specify the content type of the message. Defaults to text/plain. # * headers - Specify additional headers to be set for the message, e.g. headers 'X-Mail-Count' => 107370. # + # When a headers 'return-path' is specified, that value will be used as the 'envelope from' + # address. Setting this is useful when you want delivery notifications sent to a different address than + # the one in from. + # # The body method has special behavior. It takes a hash which generates an instance variable # named after each key in the hash containing the value that that key points to. # - # So, for example, body "account" => recipient would result + # So, for example, body :account => recipient would result # in an instance variable @account with the value of recipient being accessible in the # view. # @@ -590,14 +594,16 @@ module ActionMailer #:nodoc: def perform_delivery_smtp(mail) destinations = mail.destinations mail.ready_to_send + sender = mail['return-path'] || mail.from Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password], smtp_settings[:authentication]) do |smtp| - smtp.sendmail(mail.encoded, mail.from, destinations) + smtp.sendmail(mail.encoded, sender, destinations) end end def perform_delivery_sendmail(mail) + sendmail_settings[:arguments] += " -f \"#{mail['return-path']}\"" if mail['return-path'] IO.popen("#{sendmail_settings[:location]} #{sendmail_settings[:arguments]}","w+") do |sm| sm.print(mail.encoded.gsub(/\r/, '')) sm.flush -- cgit v1.2.3