Defect #14699

Cannot change "From" header in email notifications

Added by Zach Hamman over 5 years ago. Updated almost 4 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Code cleanup/refactoring
Target version:2.6.1
Resolution:Fixed Affected version:

Description

In Redmine 1.x (Rails 2.3), using from method in custom mailer changed the From header from Setting.mail_from.

According to Rails 3 Action Mailer documentation, mail method can receive :from header. Redmine 2.x's Mailer#mail does header.merge!{'From'=>Setting.mail_from,...}. This results in the from header being overridden and removes default functionality.

I have made a change to Mailer#mail to do header.reverse_merge! instead of header.merge!, but I am unsure if this is the best path. However, this did set up the email headers correctly.

merge_headers.diff Magnifier (488 Bytes) Vincent Robert, 2014-11-24 10:46

Associated revisions

Revision 13784
Added by Jean-Philippe Lang almost 4 years ago

Don't overwrite headers that were already set (#14699).

History

#1 Updated by Vincent Robert about 4 years ago

Here is a patch where we use the headers.reverse_merge! method instead of headers.merge!

As we can pass headers as a parameter, I think we should use a reverse_merge in order to not override our hash with default values:

  def mail(headers={}, &block)
    headers.reverse_merge! 'X-Mailer' => 'Redmine',
            'X-Redmine-Host' => Setting.host_name,
            'X-Redmine-Site' => Setting.app_title,
            'X-Auto-Response-Suppress' => 'OOF',
            'Auto-Submitted' => 'auto-generated',
            'From' => Setting.mail_from,
            'List-Id' => "<#{Setting.mail_from.to_s.gsub('@', '.')}>" 

This could be very useful in some of my plugins. Thanks

#2 Updated by Jean-Philippe Lang about 4 years ago

  • Target version set to 2.6.1

#3 Updated by Jean-Philippe Lang almost 4 years ago

  • Category changed from Email notifications to Code cleanup/refactoring
  • Status changed from New to Resolved
  • Assignee set to Jean-Philippe Lang
  • Resolution set to Fixed

Fix committed in r13784, thanks.

#4 Updated by Jean-Philippe Lang almost 4 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF