Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7572: working_return_path.diff

File working_return_path.diff, 2.0 kB (added by joost, 8 months ago)

allows headersreturn-path? to set envelope-from

  • actionmailer/lib/action_mailer/base.rb

    old new  
    4040  # * <tt>content_type</tt> - Specify the content type of the message. Defaults to <tt>text/plain</tt>. 
    4141  # * <tt>headers</tt> - Specify additional headers to be set for the message, e.g. <tt>headers 'X-Mail-Count' => 107370</tt>. 
    4242  # 
     43  # When a <tt>headers 'return-path'</tt> is specified, that value will be used as the 'envelope from' 
     44  # address. Setting this is useful when you want delivery notifications sent to a different address than 
     45  # the one in <tt>from</tt>. 
     46  # 
    4347  # The <tt>body</tt> method has special behavior. It takes a hash which generates an instance variable 
    4448  # named after each key in the hash containing the value that that key points to. 
    4549  # 
    46   # So, for example, <tt>body "account" => recipient</tt> would result 
     50  # So, for example, <tt>body :account => recipient</tt> would result 
    4751  # in an instance variable <tt>@account</tt> with the value of <tt>recipient</tt> being accessible in the  
    4852  # view. 
    4953  # 
     
    590594      def perform_delivery_smtp(mail) 
    591595        destinations = mail.destinations 
    592596        mail.ready_to_send 
     597        sender = mail['return-path'] || mail.from 
    593598 
    594599        Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain],  
    595600            smtp_settings[:user_name], smtp_settings[:password], smtp_settings[:authentication]) do |smtp| 
    596           smtp.sendmail(mail.encoded, mail.from, destinations) 
     601          smtp.sendmail(mail.encoded, sender, destinations) 
    597602        end 
    598603      end 
    599604 
    600605      def perform_delivery_sendmail(mail) 
     606        sendmail_settings[:arguments] += " -f \"#{mail['return-path']}\"" if mail['return-path'] 
    601607        IO.popen("#{sendmail_settings[:location]} #{sendmail_settings[:arguments]}","w+") do |sm| 
    602608          sm.print(mail.encoded.gsub(/\r/, '')) 
    603609          sm.flush