summaryrefslogtreecommitdiff
path: root/app/mailers/notify.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/mailers/notify.rb')
-rw-r--r--app/mailers/notify.rb37
1 files changed, 34 insertions, 3 deletions
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb
index bd438bab89a..ee27879cf40 100644
--- a/app/mailers/notify.rb
+++ b/app/mailers/notify.rb
@@ -11,6 +11,7 @@ class Notify < ActionMailer::Base
add_template_helper ApplicationHelper
add_template_helper GitlabMarkdownHelper
add_template_helper MergeRequestsHelper
+ add_template_helper EmailsHelper
default_url_options[:host] = Gitlab.config.gitlab.host
default_url_options[:protocol] = Gitlab.config.gitlab.protocol
@@ -25,21 +26,49 @@ class Notify < ActionMailer::Base
delay_for(2.seconds)
end
+ def test_email(recipient_email, subject, body)
+ mail(to: recipient_email,
+ subject: subject,
+ body: body.html_safe,
+ content_type: 'text/html'
+ )
+ end
+
+ # Splits "gitlab.corp.company.com" up into "gitlab.corp.company.com",
+ # "corp.company.com" and "company.com".
+ # Respects set tld length so "company.co.uk" won't match "somethingelse.uk"
+ def self.allowed_email_domains
+ domain_parts = Gitlab.config.gitlab.host.split(".")
+ allowed_domains = []
+ begin
+ allowed_domains << domain_parts.join(".")
+ domain_parts.shift
+ end while domain_parts.length > ActionDispatch::Http::URL.tld_length
+
+ allowed_domains
+ end
+
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.display_name = Gitlab.config.gitlab.email_display_name
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)
+ def sender(sender_id, send_from_user_email = false)
if sender = User.find(sender_id)
address = default_sender_address
address.display_name = sender.name
+
+ sender_domain = sender.email.split("@").last
+ if send_from_user_email && self.class.allowed_email_domains.include?(sender_domain)
+ address.address = sender.email
+ end
+
address.format
end
end
@@ -51,7 +80,7 @@ class Notify < ActionMailer::Base
# Returns a String containing the User's email address.
def recipient(recipient_id)
if recipient = User.find(recipient_id)
- recipient.email
+ recipient.notification_email
end
end
@@ -102,6 +131,7 @@ class Notify < ActionMailer::Base
# See: mail_answer_thread
def mail_new_thread(model, headers = {}, &block)
headers['Message-ID'] = message_id(model)
+ headers['X-GitLab-Project'] = "#{@project.name} | " if @project
mail(headers, &block)
end
@@ -116,6 +146,7 @@ class Notify < ActionMailer::Base
def mail_answer_thread(model, headers = {}, &block)
headers['In-Reply-To'] = message_id(model)
headers['References'] = message_id(model)
+ headers['X-GitLab-Project'] = "#{@project.name} | " if @project
if (headers[:subject])
headers[:subject].prepend('Re: ')