Project

General

Profile

Actions

Feature #5913

closed

Authors name in from address of email notifications

Added by Krzysztof Gałązka over 13 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Email notifications
Target version:
Start date:
2010-07-20
Due date:
% Done:

0%

Estimated time:
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.


Files

mailer.rb (10.8 KB) mailer.rb worked on 0.85 Tudor Spinache, 2010-11-03 11:51
app_models_mailer.rb.diff (2.61 KB) app_models_mailer.rb.diff worked on 0.85 Tudor Spinache, 2010-11-03 11:51
5913-authors-name-in-from-field.patch (2.39 KB) 5913-authors-name-in-from-field.patch Go MAEDA, 2019-02-14 02:42
mailer-allow-invalid-from.patch (2.67 KB) mailer-allow-invalid-from.patch Allow RFC non-compliant emission email addresses Go MAEDA, 2019-04-07 06:49

Related issues

Related to Redmine - Patch #2406: In email notification, send a email with sender as authorClosed

Actions
Related to Redmine - Feature #14727: Display pretty notification email sender nameClosed

Actions
Related to Redmine - Defect #14792: Don't add a display name and extra angle brackets in List-Id header fieldClosedGo MAEDA

Actions
Related to Redmine - Feature #31154: Reject setting RFC non-compliant emission email addressesClosedGo MAEDA

Actions
Related to Redmine - Feature #14639: Emission email address Name Closed

Actions
Has duplicate Redmine - Feature #23491: Author name in mail fromClosed

Actions
Has duplicate Redmine - Feature #16093: Emails sent out by Redmine are identicalClosed

Actions
Actions #1

Updated by Anonymous over 13 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?

Actions #2

Updated by Tudor Spinache over 13 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 ?

Actions #3

Updated by Thomas Themel almost 12 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.

Actions #4

Updated by Tudor Spinache over 11 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.

Actions #5

Updated by C Duv over 10 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

Actions #6

Updated by Zdravko Balorda about 10 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.

Actions #7

Updated by Toshi MARUYAMA over 7 years ago

Actions #8

Updated by Toshi MARUYAMA over 7 years ago

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

Updated by Toshi MARUYAMA over 7 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
Actions #10

Updated by Toshi MARUYAMA over 7 years ago

Actions #11

Updated by Toshi MARUYAMA over 7 years ago

Actions #12

Updated by Go MAEDA about 5 years ago

  • Has duplicate Feature #16093: Emails sent out by Redmine are identical added
Actions #13

Updated by Go MAEDA about 5 years 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 <>".

Actions #14

Updated by Go MAEDA about 5 years ago

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

Updated by Go MAEDA about 5 years 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|
Actions #16

Updated by Go MAEDA about 5 years ago

  • Target version set to Candidate for next major release
Actions #17

Updated by Go MAEDA about 5 years 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)"
Actions #18

Updated by Go MAEDA about 5 years 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.

Actions #19

Updated by Go MAEDA about 5 years ago

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

Updated by Go MAEDA about 5 years ago

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

Updated by Go MAEDA about 5 years 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.

Actions #22

Updated by Go MAEDA about 5 years ago

  • Status changed from Resolved to Reopened
Actions #23

Updated by Go MAEDA about 5 years 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.

Actions #24

Updated by Go MAEDA almost 5 years ago

Actions

Also available in: Atom PDF