Browse Source

Show author's name in the From field of email notifications (#5913).

Patch by Go MAEDA.


git-svn-id: http://svn.redmine.org/redmine/trunk@17870 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/4.1.0
Go MAEDA 5 years ago
parent
commit
21e503fc71
2 changed files with 29 additions and 2 deletions
  1. 10
    2
      app/models/mailer.rb
  2. 19
    0
      test/unit/mailer_test.rb

+ 10
- 2
app/models/mailer.rb View File

@@ -615,13 +615,21 @@ class Mailer < ActionMailer::Base
end

def mail(headers={}, &block)
# Add a display name to the From field if Setting.mail_from does not
# include it
mail_from = Mail::Address.new(Setting.mail_from)
if mail_from.display_name.blank? && mail_from.comments.blank?
mail_from.display_name =
(@author && @author.logged?) ? @author.name : Setting.app_title
end

headers.reverse_merge! 'X-Mailer' => 'Redmine',
'X-Redmine-Host' => Setting.host_name,
'X-Redmine-Site' => Setting.app_title,
'X-Auto-Response-Suppress' => 'All',
'Auto-Submitted' => 'auto-generated',
'From' => Setting.mail_from,
'List-Id' => "<#{Setting.mail_from.to_s.tr('@', '.')}>"
'From' => mail_from.format,
'List-Id' => "<#{mail_from.address.to_s.tr('@', '.')}>"

# Replaces users with their email addresses
[:to, :cc, :bcc].each do |key|

+ 19
- 0
test/unit/mailer_test.rb View File

@@ -249,6 +249,25 @@ class MailerTest < ActiveSupport::TestCase
assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
end

def test_from_header_with_author_name
# Use the author's name or Setting.app_title as a display name
# when Setting.mail_from does not include a display name
with_settings :mail_from => 'redmine@example.net', :app_title => 'Foo' do
# Use @author.name as a display name
Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5,
:subject => 'Issue created by Dave Lopper', :author_id => 3)
mail = last_email
assert_equal 'redmine@example.net', mail.from_addrs.first
assert_equal 'Dave Lopper <redmine@example.net>', mail.header['From'].to_s

# Use app_title if @author is nil or AnonymousUser
Mailer.deliver_test_email(User.find(1))
mail = last_email
assert_equal 'redmine@example.net', mail.from_addrs.first
assert_equal "Foo <redmine@example.net>", mail.header['From'].to_s
end
end

def test_should_not_send_email_without_recipient
news = News.first
user = news.author

Loading…
Cancel
Save