Skip to content

Adds SMTP authentication method to custom email settings page

Feature context

Sometimes customers need to specify the authentication method explicitly (e.g. M365).

We added a new enum smtp_authentication which defaults to nil. So Net::SMTP tries to figure out which AUTH method to use automatically. The EHLO response from the SMTP handshake usually contains a list of supported AUTH methods like this 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH. Sometimes the server doesn't return such information or Net::SMTP doesn't pick them or tries to use an unsupported method.

For those cases, customers may want to specify the AUTH method themselves explicitly. We can support all AUTH methods that ActionMailer supports (plain, login, cram_md5). See Mail::SMTP or Net::SMTP doc for full configuration options and defaults.

Contributes to Custom email: Net::SMTP doesn't select the corr... (#429680 - closed)

Part of Configurable e-mail address for service desk (#329990 - closed)

🎏 This feature is behind the feature flag :service_desk_custom_email which was enabled by default in 16.4.

What does this MR do and why?

Allows the user to select an explicit SMTP authentication method using a dropdown for Service Desk custom email on the projects settings page.

Related MRs

  1. Adds smtp_authentication to Service Desk Custom... (!135612 - merged) introduced the DB field and backend logic.

Follow up MRs

  1. Rescue Net::SMTPAuthenticationError (which is the error we saw when Net::SMTP doesn't know what to do) and add that error to the list of verification errors.

Screenshots or screen recordings

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

Before After
Screenshot_2023-11-03_at_14.59.15 Screenshot_2023-11-03_at_14.58.35

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. If you haven't set up incoming_email or service_desk_email for email ingestion, please add this to your gitlab.yml file in the development: section. Please restart GDK with gdk restart:
    incoming_email:
      enabled: true
      address: "incoming+%{key}@example.com"
    This will allow you to see the Service Desk section in the settings and generate project-specific email addresses. You won't be able to ingest emails, but we don't need that here.
  2. Visit http://127.0.0.1:3000/flightjs/Flight/edit and expand the Service Desk section. Please find the Configure a custom email address card.
  3. (Optional) If it's not available, you probably need to enable the feature flag (enabled by default).
    project = Project.find(7)
    Feature.enable(:service_desk_custom_email, project)
  4. The form should contain the form item SMTP authentication method with a dropdown with the following options:
    1. Use method supported by the server (recommended)
    2. Plain
    3. Login
    4. CRAM-MD5
  5. Fill in some example values. Feel free to use these:
    1. support@example.com
    2. smtp.gmail.com (SMTP address needs to be resolvable from the public internet)
    3. 587
    4. support@example.com
    5. supersecret
    6. Login <-- SMTP authentication method
  6. Open the developer tools and select the Network tab to check the payload of the POST request.
  7. Select Save and test connection. The verification will obviously fail quite fast, but we're only interested in checking whether the authentication method value is transported and saved correctly.
  8. The payload of the custom_email POST request should contain smtp_authentication: "login".
  9. Now let's check whether the value has been saved correctly. In the rails console run the following:
    Project.find(7).service_desk_custom_email_credential
    You should see something like smtp_authentication: "login.
  10. (Optional) To roll back all changes, select Reset custom email or run the following snippet:
    project = Project.find(7)
    current_user = User.first
    ::ServiceDesk::CustomEmails::DestroyService.new(
      project: project,
      current_user: current_user
    ).execute

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