Feature #5913

Authors name in from address of email notifications

Added by Krzysztof Gałązka over 9 years ago. Updated 6 months ago.

Status:ClosedStart date:2010-07-20
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Email notifications
Target version:4.1.0
Resolution:Fixed

Description

In mail notification created by Redmine 'FROM' address in headers
is set to Setting.mail_form. It would be useful to add name of
author to this address. You would know who is working on issue
without opening mail. I've changed line in app/models/mailer.rb
in initialize_defaults method:

from Setting.mail_from

to

@author ||= User.current
from "#{@author.name} <#{Setting.mail_form}>"

It seams to work, but I'm not sure if it wont break anything.

mailer.rb Magnifier - worked on 0.85 (10.8 KB) Tudor Spinache, 2010-11-03 11:51

app_models_mailer.rb.diff Magnifier - worked on 0.85 (2.61 KB) Tudor Spinache, 2010-11-03 11:51

5913-authors-name-in-from-field.patch Magnifier (2.39 KB) Go MAEDA, 2019-02-14 02:42

mailer-allow-invalid-from.patch Magnifier - Allow RFC non-compliant emission email addresses (2.67 KB) Go MAEDA, 2019-04-07 06:49


Related issues

Related to Redmine - Patch #2406: In email notification, send a email with sender as author Closed
Related to Redmine - Feature #14727: Display pretty notification email sender name Closed
Related to Redmine - Defect #14792: Don't add a display name and extra angle brackets in List... Closed
Related to Redmine - Feature #31154: Reject setting RFC non-compliant emission email addresses Closed
Related to Redmine - Feature #14639: Emission email address Name Closed
Duplicated by Redmine - Feature #23491: Author name in mail from Closed
Duplicated by Redmine - Feature #16093: Emails sent out by Redmine are identical Closed

Associated revisions

Revision 17870
Added by Go MAEDA 8 months ago

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

Patch by Go MAEDA.

Revision 18050
Added by Go MAEDA 6 months ago

Don't raise an exception when the emission email address is not RFC compliant (#5913).

Patch by Go MAEDA.

History

#1 Updated by Anonymous about 9 years ago

I like that idea. Have you had any bad experience with it?

Also, for clarification: who is identified as User.current? The one currently logged in triggering the action that sends a notification?

#2 Updated by Tudor Spinache almost 9 years ago

I managed to make it work 100% in ver 0.85, however after upgrading to 0.95, because the ruby version changed, the old mailer.rb didn't work anymore. Tested on 1.0.0 but obviously, again with the same result.

I put attached my 0.85 working mailer.rb and the patch I used to make it.

Is it possible that one of the ruby gurus out there to "translate" the mailer.rb or the patch to the latest version of ruby ?

#3 Updated by Thomas Themel over 7 years ago

I implemented this for 1.4.1 by just adding one line in models/mailer.rb -

    if @author && @author.logged?
      redmine_headers 'Sender' => @author.login
    end

to

    if @author && @author.logged?
      redmine_headers 'Sender' => @author.login
      from @author.firstname + " " + @author.lastname + " via " + Setting.app_title + "<" + Setting.mail_from + ">" 
    end

Seems to work well enough for the moment, though of course it would be nicer if this was achievable via configuration instead of patching the code.

#4 Updated by Tudor Spinache about 7 years ago

Hi Thomas,

Thanks a lot for your help. Trying to add the same for ver. 2.0.3-1 but got the following in dmesg:

NoMethodError (undefined method `from' for #<Mailer:0xb4b2712c>):
  app/models/mailer.rb:389:in `mail'
  app/models/mailer.rb:48:in `issue_add'
  app/models/mailer.rb:417:in `initialize'
  app/models/mailer.rb:430:in `method_missing'
  app/models/issue_observer.rb:20:in `after_create'
  app/controllers/issues_controller.rb:148:in `create'

This happens when trying to add new issue or update an existing one.
Any help would be mostly appreciated.

Tudor.

#5 Updated by C Duv about 6 years ago

Just ran into the same issue (moving from 1.0.1 to 2.3.2) and was quite surprise to discover that e-mails are now From the e-mail set in Setting.mail_from (in Configuration panel) whereas it was the full name and e-mail address of the author back in 1.x (at least in 1.0.1).

Since last comment from Tudor Spinache a year ago, things might have changed a bit.

In source:/trunk/app/models/mailer.rb@12015#L377 header From is forced to take the value of Setting.mail_from. But removing this line, the From header is now correct in regards of what is specified when calling the Mailer::mail() method but I suspect any e-mail sending code not specifying from option will stop working.

Couldn't be we simply do the following changes?:

--- /master/app/models/mailer.rb    Sun Aug 04 03:54:48 2013
+++ /from_header-fix/app/models/mailer.rb    Sun Aug 04 03:53:47 2013
@@ -385,9 +385,13 @@
             '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('@', '.')}>" 

+    # Set From header if not set
+    if !headers[:from]
+      headers[:from] = Setting.mail_from
+    end
+    
     # Removes the author from the recipients and cc
     # if he doesn't want to receive notifications about what he does
     if @author && @author.logged? && @author.pref.no_self_notified

#6 Updated by Zdravko Balorda over 5 years ago

Would't merely reply-to field solve this problem:

+           'Reply-To' => User.current.mail,

my Evolution mail client would reply to this field.
Regards, Zdravko.

#7 Updated by Toshi MARUYAMA about 3 years ago

#8 Updated by Toshi MARUYAMA about 3 years ago

  • Related to Patch #2406: In email notification, send a email with sender as author added

#9 Updated by Toshi MARUYAMA about 3 years ago

From #23491.

--- app/models/mailer.rb        (revision 15732)
+++ app/models/mailer.rb        (working copy)
@@ -438,7 +438,7 @@
             'X-Redmine-Site' => Setting.app_title,
             'X-Auto-Response-Suppress' => 'All',
             'Auto-Submitted' => 'auto-generated',
-            'From' => Setting.mail_from,
+            'From' => "#{User.current.name} <#{Setting.mail_from}>",
             'List-Id' => "<#{Setting.mail_from.to_s.gsub('@', '.')}>" 

     # Replaces users with their email addresses

#10 Updated by Toshi MARUYAMA about 3 years ago

#11 Updated by Toshi MARUYAMA about 3 years ago

#12 Updated by Go MAEDA 8 months ago

  • Duplicated by Feature #16093: Emails sent out by Redmine are identical added

#13 Updated by Go MAEDA 8 months ago

I like this idea. Probably this feature satisfies some of the people who requested to change the emission address to the author's email address (#241, #247, #2406, ...).

Users can get more information from their emails list and they can decide whether to move the email to the trash without opening it:P And the good point of this idea is that it does not affect existing features like Email Receiving (see the discussion #2406#note-3).

As mentioned in #16093, GitHub already implements this. The format of From field of their notification emails is "user's name <>".

#14 Updated by Go MAEDA 8 months ago

  • Related to Feature #14727: Display pretty notification email sender name added

#15 Updated by Go MAEDA 8 months ago

The following change sets the author's name in From field if Setting.mail_from does not include display name. For example, it inserts the author's name if the value of Setting.mail_from is "", but does not if the value includes display name like "Redmine <>".

diff --git a/app/models/mailer.rb b/app/models/mailer.rb
index 492ca976d..b251f7c47 100644
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -615,13 +615,20 @@ class Mailer < ActionMailer::Base
   end

   def mail(headers={}, &block)
+    # Insert author's name to the From field if display name
+    # is not included in Setting.mail_from
+    mail_from = Mail::Address.new(Setting.mail_from)
+    if @author && @author.logged? && mail_from.display_name.blank? && mail_from.comments.blank?
+      mail_from.display_name = @author.name
+    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|

#16 Updated by Go MAEDA 8 months ago

  • Target version set to Candidate for next major release

#17 Updated by Go MAEDA 8 months ago

Here is a patch with a test.

This feature inserts a display name to From field of emails if Setting.mail_from does not include it.

The display name is the name of the user who made an action triggers the email notification. For notifications that an author is not available such as reminders and notifications triggered by an anonymous user, Setting.app_title is used as a display name.

If Setting.mail_from includes a display name, it is preserved and an author name is never inserted. This is the same behavior with the current version of Redmine (tested by MailerTest#test_from_header). Admins those who don't want to show the authors name in From field can disable it by settings the "Emission email address" to a value with a display name like "Redmine <redmine@example.net>" instead of "redmine@example.net".

Setting.mail_from From field in the message header
"redmine@example.net" "#{@author.name} <redmine.example.net>"
"#{@Setting.app_title} <redmine.example.net>" (when @author is nil or anonymous)
"Foo <redmine@example.net>" "Foo <redmine@example.net>"
"redmine@example.net (Foo)" "redmine@example.net (Foo)"

#18 Updated by Go MAEDA 8 months ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Target version changed from Candidate for next major release to 4.1.0
  • Resolution set to Fixed

Committed.

#19 Updated by Go MAEDA 8 months ago

  • Related to Defect #14792: Don't add a display name and extra angle brackets in List-Id header field added

#20 Updated by Go MAEDA 7 months ago

  • Related to Feature #31154: Reject setting RFC non-compliant emission email addresses added

#21 Updated by Go MAEDA 7 months ago

As I reported as #31154, RFC non-compliant emission email addresses causes Mail::Field::IncompleteParseError and notification emails are not delivered after r17870.

The attached patch deal with the issue. After the patch applied, app/models/mailer.rb behaves same as before r17870 when Mail::Address raises an exception due to an RFC non-compliant emission email address.

#22 Updated by Go MAEDA 7 months ago

  • Status changed from Resolved to Reopened

#23 Updated by Go MAEDA 6 months ago

  • Status changed from Reopened to Closed

Go MAEDA wrote:

As I reported as #31154, RFC non-compliant emission email addresses causes Mail::Field::IncompleteParseError and notification emails are not delivered after r17870.

Committed the fix in r18050.

#24 Updated by Go MAEDA 5 months ago

Also available in: Atom PDF