Skip to content

Adds service desk custom email verification result email

Marc Saleiko requested to merge ms-service-desk-verification-result-email into master

Feature context

Click to expand 👇

Right now it is not possible to customize the Service Desk email address (intake and sending) in its entirety. On self-hosted instances you have more control over the used addresses, but you will still have a rather cryptic target email address for a specific service desk in a project. For .com users it's currently not possible to customize the Service Desk email at all.

There is a proposal and a further exploration around this issue. A summary of the solution path is the following: Users set up their custom email to forward all emails to the cryptic Service Desk email and provide SMTP credentials so we can send emails on their behalf. This way customers seeking support will only see the custom email address in their communication.

There is further discussion about improving and changing the general infrastructure, but this approach is a MVC to solve the issue for our customers.

🗺 How does it contribute to the whole feature?

Click to expand 👇

This MR is the second part in a series of MRs that will follow in order to complete this feature. See #329990 (comment 1227384943) for a detailed breakdown. Here's a summary:

  1. Using SMTP credentials. Foundation work. Add Service Desk custom email foundation (!108017 - merged)
  2. 🎯 Verify email ownership, correct function and setup Part 2: Move credentials to own table to address additional access methods
  3. Ingest replies from custom email
  4. Add settings and validation to Settings page
  5. Add documentation

What does this MR do and why?

🎏 The feature as a whole is hidden behind the feature flag service_desk_custom_email and is not enabled on production yet

This MR adds one of three emails we need for Service Desk custom email address setup end verification. This email will be sent out, once the verification process is finished and will provide additional info whether it succeeded or failed. The user who triggered the verification and all project owners will receive this notification message (logic will be delivered in an upcoming MR via a service).

The purpose of the email is to inform about the outcome of the verification process for the Service Desk custom email address.

Merge request dependency

This MR depends on Adds service desk verification triggered email (!116037 - merged) as it uses newly introduced instance methods in NotifyPreview. I will keep this MR updated with all changes in the parent MR and change the merge target to master once the dependency has been merged. This MR has also been added as a merge request dependency.

!116037 (merged) has been merged.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Email: service_desk_verification_result_email

Type Case preview link HTML Text
success - local preview link image image
error incorrect_from local preview link image image
error incorrect_token local preview link image image
error invalid_credentials local preview link image image
error mail_not_received_within_timeframe local preview link image image
error smtp_host_issue local preview link image image

How to set up and validate locally

Easy path (rails mailer previews)

  1. Open mailer previews locally and view the HTML and text version of this mail
  2. http://127.0.0.1:3000/rails/mailers/notify/service_desk_verification_result_email_for_verified_state
  3. http://127.0.0.1:3000/rails/mailers/notify/service_desk_verification_result_email_for_incorrect_from_error
  4. http://127.0.0.1:3000/rails/mailers/notify/service_desk_verification_result_email_for_incorrect_token_error
  5. http://127.0.0.1:3000/rails/mailers/notify/service_desk_verification_result_email_for_invalid_credentials_error
  6. http://127.0.0.1:3000/rails/mailers/notify/service_desk_verification_result_email_for_mail_not_received_within_timeframe_error
  7. http://127.0.0.1:3000/rails/mailers/notify/service_desk_verification_result_email_for_smtp_host_issue_error

Letter opener path (send via console)

  1. Find a project ID in your installation that you have not used for any Service Desk (including CustomEmailCredentials and CustomEmailVerification testing) setup and testing. Why? It makes these steps a lot easier 🙂
  2. Open the rails console bin/rails c in gitlab folder
  3. Find the project by id
    project = Project.find(5) # Where 5 is your project id
  4. Create ServiceDeskSetting entry (which holds Service Desk related meta info and custom email stuff)
    settings = ServiceDeskSetting.create!(
      project: project,
      custom_email: 'user@gmail.com'
    )
  5. Create ServiceDesk::CustomEmailCredential
    credential = ServiceDesk::CustomEmailCredential.create!(
       project: project,
       smtp_address: 'smtp.gmail.com', # Use gmail, because Gitlab::UrlBlocker resolves DNS
       smtp_port: 587,
       smtp_username: 'user@gmail.com',
       smtp_password: 'supersecret'
     )
  6. Create ServiceDesk::CustomEmailVerification entry (which holds meta info for the state of the verification process)
    verification = ServiceDesk::CustomEmailVerification.create!(
       project: project,
       token: 'XXXXXXXXXXXX',
       triggerer: User.first, # that should be @root, that's fine
       triggered_at: Time.current,
       state: 1 # which is "verified"
     )
  7. Reset associations on project, because we access these objects from ServiceDeskSetting internally via project
    project.reset
  8. Actually send the mail
    Notify.service_desk_verification_result_email(settings, 'owner@example.com').deliver
  9. Open Letter Opener at http://127.0.0.1:3000/rails/letter_opener/. You should see a new email that states that the verification was successful.
  10. You can also check different email states, by running this script. You should see 5 additional emails in letter opener that represent all possible states of the email:
    errors = %w[incorrect_token incorrect_from mail_not_received_within_timeframe invalid_credentials smtp_host_issue]
    errors.each do |error_identifier|
      verification.update!(state: 2, error: error_identifier)
      project.reset
      Notify.service_desk_verification_result_email(settings, 'owner@example.com').deliver
    end
  11. (Optional) clean up the mess and remove entries
    settings.destroy
    credential.destroy
    verification.destroy

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Marc Saleiko

Merge request reports