Configure gitlab mailing for Microsoft Graph API application

Problem to solve

Hi I’m trying to enable mail via Microsoft Graph API on my self managed instance.
The mail should be send via a registered application, which I can confirm works, as I’m also using it for another service.
It seems like the docs only provide information on how to do this when sending mail on behalf of a user. I tried leaving out the microsoft_graph_mailer_user_id configuration, but this results in following error when trying to send a test mail via rails console:
/opt/gitlab/embedded/service/gitlab-rails/vendor/gems/microsoft_graph_mailer/lib/microsoft_graph_mailer/delivery.rb:14:in `block in initialize': 'user_id' is missing (MicrosoftGraphMailer::ConfigurationError)

Configuration

Here is my config with sensitive data removed:

gitlab_rails['gitlab_email_from'] = 'no-reply@example.com'
gitlab_rails['gitlab_email_reply_to'] = 'no-reply@example.com'
gitlab_rails['microsoft_graph_mailer_enabled'] = true
gitlab_rails['microsoft_graph_mailer_tenant'] = "<TENANT_ID>"
gitlab_rails['microsoft_graph_mailer_client_id'] = "<CLIENT_ID>"
gitlab_rails['microsoft_graph_mailer_client_secret'] = "<CLIENT_SECRET_ID>"
gitlab_rails['microsoft_graph_mailer_azure_ad_endpoint'] = "https://login.microsoftonline.com"
gitlab_rails['microsoft_graph_mailer_graph_endpoint'] = "https://graph.microsoft.com"

Versions

Please select whether options apply, and add the version information.

Versions
GitLab CE v17.3.1 Docker

Seems like this was a misunderstanding on my part.
I think you have to supply a user_id so Microsoft can reference the User Account. I thought this relation would happen automatically with the supplied email.
After adding the service account to the microsoft_graph_mailer_user_id configuration everything works!

1 Like