Vote #67646
完了Authors name in from address of email notifications
0%
説明
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.
journals
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?
--------------------------------------------------------------------------------
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 ?
--------------------------------------------------------------------------------
I implemented this for 1.4.1 by just adding one line in @models/mailer.rb@ -
<pre>
if @author && @author.logged?
redmine_headers 'Sender' => @author.login
end
</pre>
to
<pre>
if @author && @author.logged?
redmine_headers 'Sender' => @author.login
from @author.firstname + " " + @author.lastname + " via " + Setting.app_title + "<" + Setting.mail_from + ">"
end
</pre>
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.
--------------------------------------------------------------------------------
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:
<pre>
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'
</pre>
This happens when trying to add new issue or update an existing one.
Any help would be mostly appreciated.
Tudor.
--------------------------------------------------------------------------------
Just ran into the same issue (moving from version:1.0.1 to version: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 version: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?:
<pre>
<code class="diff">
--- /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
</code>
</pre>
--------------------------------------------------------------------------------
Would't merely reply-to field solve this problem:
<pre>
+ 'Reply-To' => User.current.mail,
</pre>
my Evolution mail client would reply to this field.
Regards, Zdravko.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
From #23491.
<pre><code class="diff">
--- 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
</code></pre>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
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 [[RedmineReceivingEmails| 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 <notifications@github.com>".
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
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 "foo@example.com", but does not if the value includes display name like "Redmine <foo@example.com>".
<pre><code class="diff">
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|
</code></pre>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
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 |
|/2. @"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)"@ |
--------------------------------------------------------------------------------
Committed.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
related_issues
relates,Closed,2406,In email notification, send a email with sender as author
relates,Closed,14727,Display pretty notification email sender name
relates,Closed,14792,Don't add a display name and extra angle brackets in List-Id header field
relates,Closed,31154,Reject setting RFC non-compliant emission email addresses
relates,Closed,14639,Emission email address Name
duplicates,Closed,23491,Author name in mail from
duplicates,Closed,16093,Emails sent out by Redmine are identical