diff options
-rw-r--r-- | app/mailers/emails/service_desk.rb | 34 | ||||
-rw-r--r-- | app/mailers/previews/notify_preview.rb | 8 | ||||
-rw-r--r-- | app/views/notify/service_desk_custom_email_verification_email.text.erb | 4 | ||||
-rw-r--r-- | locale/gitlab.pot | 3 | ||||
-rw-r--r-- | spec/mailers/emails/service_desk_spec.rb | 22 |
5 files changed, 69 insertions, 2 deletions
diff --git a/app/mailers/emails/service_desk.rb b/app/mailers/emails/service_desk.rb index 3bab788cd57..f2327239699 100644 --- a/app/mailers/emails/service_desk.rb +++ b/app/mailers/emails/service_desk.rb @@ -43,6 +43,36 @@ module Emails inject_service_desk_custom_email(mail_answer_thread(@issue, options)) end + def service_desk_custom_email_verification_email(service_desk_setting) + @service_desk_setting = service_desk_setting + + email_sender = sender( + User.support_bot.id, + send_from_user_email: false, + sender_name: @service_desk_setting.outgoing_name, + sender_email: @service_desk_setting.custom_email + ) + + @verification_token = @service_desk_setting.custom_email_verification.token + + subject = format(s_("Notify|Verify custom email address %{email} for %{project_name}"), + email: @service_desk_setting.custom_email, + project_name: @service_desk_setting.project.name + ) + + options = { + from: email_sender, + to: @service_desk_setting.custom_email_address_for_verification, + subject: subject, + content_type: "text/plain" + } + # Outgoing emails from GitLab usually have this set to true. + # Service Desk email ingestion ignores auto generated emails. + headers["Auto-Submitted"] = "no" + + inject_service_desk_custom_email(mail_with_locale(options), force: true) + end + def service_desk_verification_triggered_email(service_desk_setting, recipient) @service_desk_setting = service_desk_setting @triggerer = @service_desk_setting.custom_email_verification.triggerer @@ -80,8 +110,8 @@ module Emails end end - def inject_service_desk_custom_email(mail) - return mail unless service_desk_custom_email_enabled? + def inject_service_desk_custom_email(mail, force: false) + return mail if !service_desk_custom_email_enabled? && !force return mail unless @service_desk_setting.custom_email_credential.present? mail.delivery_method(::Mail::SMTP, @service_desk_setting.custom_email_credential.delivery_options) diff --git a/app/mailers/previews/notify_preview.rb b/app/mailers/previews/notify_preview.rb index 61d77d82d9a..f6c4b05ab39 100644 --- a/app/mailers/previews/notify_preview.rb +++ b/app/mailers/previews/notify_preview.rb @@ -213,6 +213,14 @@ class NotifyPreview < ActionMailer::Preview Notify.service_desk_thank_you_email(issue.id).message end + def service_desk_custom_email_verification_email + cleanup do + setup_service_desk_custom_email_objects + + Notify.service_desk_custom_email_verification_email(service_desk_setting).message + end + end + def service_desk_verification_triggered_email cleanup do setup_service_desk_custom_email_objects diff --git a/app/views/notify/service_desk_custom_email_verification_email.text.erb b/app/views/notify/service_desk_custom_email_verification_email.text.erb new file mode 100644 index 00000000000..c3d49a67263 --- /dev/null +++ b/app/views/notify/service_desk_custom_email_verification_email.text.erb @@ -0,0 +1,4 @@ +This email is auto-generated. It verifies the ownership of the entered Service Desk custom email address and +correct functionality of email forwarding. + +Verification token: <%= @verification_token %> diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 7d48e6df6e8..1798532669f 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -29842,6 +29842,9 @@ msgstr "" msgid "Notify|Verification for custom email %{email} for %{project_name} triggered" msgstr "" +msgid "Notify|Verify custom email address %{email} for %{project_name}" +msgstr "" + msgid "Notify|You don't have access to the project." msgstr "" diff --git a/spec/mailers/emails/service_desk_spec.rb b/spec/mailers/emails/service_desk_spec.rb index b81c0ec8617..e76da38998b 100644 --- a/spec/mailers/emails/service_desk_spec.rb +++ b/spec/mailers/emails/service_desk_spec.rb @@ -327,6 +327,28 @@ RSpec.describe Emails::ServiceDesk, feature_category: :service_desk do end end + describe '.service_desk_custom_email_verification_email' do + subject { Notify.service_desk_custom_email_verification_email(service_desk_setting) } + + it_behaves_like 'a custom email verification process email' + + it 'uses service bot name and custom email as sender' do + expect_sender(User.support_bot, sender_email: service_desk_setting.custom_email) + end + + it 'forcibly uses SMTP delivery method and has correct settings' do + expect_service_desk_custom_email_delivery_options(service_desk_setting) + end + + it 'uses verification email address as recipient' do + expect(subject.to).to eq([service_desk_setting.custom_email_address_for_verification]) + end + + it 'contains verification token' do + is_expected.to have_body_text("Verification token: #{verification.token}") + end + end + describe '.service_desk_verification_triggered_email' do before do service_desk_setting.custom_email_verification.triggerer = user |