summaryrefslogtreecommitdiff
path: root/app/mailers/notify.rb
diff options
context:
space:
mode:
authorPierre de La Morinerie <pierre@capitainetrain.com>2014-02-17 18:49:42 +0100
committerPierre de La Morinerie <pierre@capitainetrain.com>2014-02-19 18:25:18 +0100
commit96dded3ec8401e9832b3888338f37c846bd43583 (patch)
treeae782ede2d7b2668c7cc659a1ebb03b086916502 /app/mailers/notify.rb
parent57cb1ca7917f27f2c7500858fb66d53b3ea49783 (diff)
downloadgitlab-ce-96dded3ec8401e9832b3888338f37c846bd43583.tar.gz
Send emails from the author
This changes the email "From" field from "gitlab@example.com" to either: * "John Doe <gitlab@example.com>" if the author of the action is known, * "GitLab <gitlab@example.com>" otherwise. Rationale: this allow mails to appear as if they were sent by the author. It appears in the mailbox more like a real discussion between the sender and the receiver ("John sent: we should refactor this") and less like a robot notifying about something.
Diffstat (limited to 'app/mailers/notify.rb')
-rw-r--r--app/mailers/notify.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb
index 3a4c9cf73b9..554f53cf148 100644
--- a/app/mailers/notify.rb
+++ b/app/mailers/notify.rb
@@ -15,7 +15,7 @@ class Notify < ActionMailer::Base
default_url_options[:port] = Gitlab.config.gitlab.port unless Gitlab.config.gitlab_on_standard_port?
default_url_options[:script_name] = Gitlab.config.gitlab.relative_url_root
- default from: Gitlab.config.gitlab.email_from
+ default from: Proc.new { default_sender_address.format }
default reply_to: "noreply@#{Gitlab.config.gitlab.host}"
# Just send email with 2 seconds delay
@@ -25,6 +25,23 @@ class Notify < ActionMailer::Base
private
+ # The default email address to send emails from
+ def default_sender_address
+ address = Mail::Address.new(Gitlab.config.gitlab.email_from)
+ address.display_name = "GitLab"
+ address
+ end
+
+ # Return an email address that displays the name of the sender.
+ # Only the displayed name changes; the actual email address is always the same.
+ def sender(sender_id)
+ if sender = User.find(sender_id)
+ address = default_sender_address
+ address.display_name = sender.name
+ address.format
+ end
+ end
+
# Look up a User by their ID and return their email address
#
# recipient_id - User ID