diff options
author | Pierre de La Morinerie <pierre@capitainetrain.com> | 2014-02-17 21:49:42 +0400 |
---|---|---|
committer | Pierre de La Morinerie <pierre@capitainetrain.com> | 2014-02-19 21:25:18 +0400 |
commit | 96dded3ec8401e9832b3888338f37c846bd43583 (patch) | |
tree | ae782ede2d7b2668c7cc659a1ebb03b086916502 /app/mailers | |
parent | 57cb1ca7917f27f2c7500858fb66d53b3ea49783 (diff) |
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')
-rw-r--r-- | app/mailers/emails/issues.rb | 14 | ||||
-rw-r--r-- | app/mailers/emails/merge_requests.rb | 14 | ||||
-rw-r--r-- | app/mailers/emails/notes.rb | 12 | ||||
-rw-r--r-- | app/mailers/emails/projects.rb | 4 | ||||
-rw-r--r-- | app/mailers/notify.rb | 19 |
5 files changed, 47 insertions, 16 deletions
diff --git a/app/mailers/emails/issues.rb b/app/mailers/emails/issues.rb index dece5112c9e..3adb47dc5b1 100644 --- a/app/mailers/emails/issues.rb +++ b/app/mailers/emails/issues.rb @@ -3,15 +3,17 @@ module Emails def new_issue_email(recipient_id, issue_id) @issue = Issue.find(issue_id) @project = @issue.project - mail(to: recipient(recipient_id), + mail(from: sender(@issue.author_id), + to: recipient(recipient_id), subject: subject("#{@issue.title} (##{@issue.iid})")) end - def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id) + def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id, updated_by_user_id) @issue = Issue.find(issue_id) @previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id @project = @issue.project - mail(to: recipient(recipient_id), + mail(from: sender(updated_by_user_id), + to: recipient(recipient_id), subject: subject("#{@issue.title} (##{@issue.iid})")) end @@ -19,7 +21,8 @@ module Emails @issue = Issue.find issue_id @project = @issue.project @updated_by = User.find updated_by_user_id - mail(to: recipient(recipient_id), + mail(from: sender(updated_by_user_id), + to: recipient(recipient_id), subject: subject("#{@issue.title} (##{@issue.iid})")) end @@ -28,7 +31,8 @@ module Emails @issue_status = status @project = @issue.project @updated_by = User.find updated_by_user_id - mail(to: recipient(recipient_id), + mail(from: sender(updated_by_user_id), + to: recipient(recipient_id), subject: subject("#{@issue.title} (##{@issue.iid})")) end end diff --git a/app/mailers/emails/merge_requests.rb b/app/mailers/emails/merge_requests.rb index 39c02ca07c9..0845e14edc7 100644 --- a/app/mailers/emails/merge_requests.rb +++ b/app/mailers/emails/merge_requests.rb @@ -3,15 +3,17 @@ module Emails def new_merge_request_email(recipient_id, merge_request_id) @merge_request = MergeRequest.find(merge_request_id) @project = @merge_request.project - mail(to: recipient(recipient_id), + mail(from: sender(@merge_request.author_id), + to: recipient(recipient_id), subject: subject("#{@merge_request.title} (!#{@merge_request.iid})")) end - def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id) + def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id, updated_by_user_id) @merge_request = MergeRequest.find(merge_request_id) @previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id @project = @merge_request.project - mail(to: recipient(recipient_id), + mail(from: sender(updated_by_user_id), + to: recipient(recipient_id), subject: subject("#{@merge_request.title} (!#{@merge_request.iid})")) end @@ -19,14 +21,16 @@ module Emails @merge_request = MergeRequest.find(merge_request_id) @updated_by = User.find updated_by_user_id @project = @merge_request.project - mail(to: recipient(recipient_id), + mail(from: sender(updated_by_user_id), + to: recipient(recipient_id), subject: subject("#{@merge_request.title} (!#{@merge_request.iid})")) end def merged_merge_request_email(recipient_id, merge_request_id) @merge_request = MergeRequest.find(merge_request_id) @project = @merge_request.project - mail(to: recipient(recipient_id), + mail(from: sender(@merge_request.author_id_of_changes), + to: recipient(recipient_id), subject: subject("#{@merge_request.title} (!#{@merge_request.iid})")) end end diff --git a/app/mailers/emails/notes.rb b/app/mailers/emails/notes.rb index b727301df5c..00b127da429 100644 --- a/app/mailers/emails/notes.rb +++ b/app/mailers/emails/notes.rb @@ -4,7 +4,8 @@ module Emails @note = Note.find(note_id) @commit = @note.noteable @project = @note.project - mail(to: recipient(recipient_id), + mail(from: sender(@note.author_id), + to: recipient(recipient_id), subject: subject("#{@commit.title} (#{@commit.short_id})")) end @@ -12,7 +13,8 @@ module Emails @note = Note.find(note_id) @issue = @note.noteable @project = @note.project - mail(to: recipient(recipient_id), + mail(from: sender(@note.author_id), + to: recipient(recipient_id), subject: subject("#{@issue.title} (##{@issue.iid})")) end @@ -20,14 +22,16 @@ module Emails @note = Note.find(note_id) @merge_request = @note.noteable @project = @note.project - mail(to: recipient(recipient_id), + mail(from: sender(@note.author_id), + to: recipient(recipient_id), subject: subject("#{@merge_request.title} (!#{@merge_request.iid})")) end def note_wall_email(recipient_id, note_id) @note = Note.find(note_id) @project = @note.project - mail(to: recipient(recipient_id), + mail(from: sender(@note.author_id), + to: recipient(recipient_id), subject: subject("Note on wall")) end end diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb index 428d74d83c6..46f24e9fb7c 100644 --- a/app/mailers/emails/projects.rb +++ b/app/mailers/emails/projects.rb @@ -22,7 +22,9 @@ module Emails @diffs = compare.diffs @branch = branch - mail(to: recipient, subject: subject("New push to repository")) + mail(from: sender(author_id), + to: recipient, + subject: subject("New push to repository")) end end end 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 |