Skip to content

Commit c7aad63

Browse files
author
Francis Caron
committed
Add Microsoft Graph Mailer support
Adds support for GitLab's native Microsoft Graph Mailer to send emails via the Microsoft Graph API with OAuth 2.0 client credentials, as an alternative to SMTP. This addresses the deprecation of basic auth for SMTP AUTH on Exchange Online. Closes #3239
1 parent d09e2a4 commit c7aad63

4 files changed

Lines changed: 91 additions & 1 deletion

File tree

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,26 @@ docker run --name gitlab -d \
437437

438438
Please refer the [Available Configuration Parameters](#available-configuration-parameters) section for the list of SMTP parameters that can be specified.
439439

440+
##### Microsoft Graph Mailer
441+
442+
As Microsoft is retiring basic authentication for SMTP AUTH on Exchange Online, mail delivery via SMTP using a Microsoft 365 mailbox is no longer viable for many tenants. The image supports GitLab's native Microsoft Graph Mailer, which sends emails via the Microsoft Graph API using OAuth 2.0 client credentials.
443+
444+
To enable it, register an application in Azure AD, grant it the `Mail.Send` **Application** permission (not Delegated), and have an administrator consent to it. Then start the container with:
445+
446+
```bash
447+
docker run --name gitlab -d \
448+
--env 'MICROSOFT_GRAPH_MAILER_ENABLED=true' \
449+
--env 'MICROSOFT_GRAPH_MAILER_USER_ID=00000000-0000-0000-0000-000000000000' \
450+
--env 'MICROSOFT_GRAPH_MAILER_TENANT=contoso.onmicrosoft.com' \
451+
--env 'MICROSOFT_GRAPH_MAILER_CLIENT_ID=11111111-1111-1111-1111-111111111111' \
452+
--env 'MICROSOFT_GRAPH_MAILER_CLIENT_SECRET=YOUR_CLIENT_SECRET' \
453+
--env 'GITLAB_EMAIL=sender@contoso.com' \
454+
--volume /srv/docker/gitlab/gitlab:/home/git/data \
455+
sameersbn/gitlab:18.11.0
456+
```
457+
458+
`MICROSOFT_GRAPH_MAILER_USER_ID` is the Object ID of the Microsoft 365 user whose mailbox will be used, and `GITLAB_EMAIL` must be that user's primary email address. `SMTP_ENABLED` should stay at its default (`false`) when Graph Mailer is used. Please refer the [Available Configuration Parameters](#available-configuration-parameters) section for the list of Microsoft Graph Mailer parameters that can be specified.
459+
440460
##### Reply by email
441461

442462
Since version `8.0.0` GitLab adds support for commenting on issues by replying to emails.
@@ -2019,6 +2039,34 @@ Specify the `ca_path` parameter for SMTP email configuration. Defaults to `/home
20192039

20202040
Specify the `ca_file` parameter for SMTP email configuration. Defaults to `/home/git/data/certs/ca.crt`.
20212041

2042+
##### `MICROSOFT_GRAPH_MAILER_ENABLED`
2043+
2044+
Enable mail delivery via Microsoft Graph API. Defaults to `false`. When enabled, emails are sent using OAuth 2.0 client credentials via the Microsoft Graph `sendMail` endpoint instead of SMTP. Requires an Azure App Registration with the `Mail.Send` Application permission granted and admin-consented. When both `SMTP_ENABLED` and `MICROSOFT_GRAPH_MAILER_ENABLED` are `false`, GitLab mail delivery is disabled.
2045+
2046+
##### `MICROSOFT_GRAPH_MAILER_USER_ID`
2047+
2048+
The Object ID (GUID) of the Microsoft 365 user to send mail as. This must match the user whose mailbox the emails are sent from. `GITLAB_EMAIL` should match the primary email address of this user.
2049+
2050+
##### `MICROSOFT_GRAPH_MAILER_TENANT`
2051+
2052+
The Azure AD tenant ID (GUID) or tenant domain (e.g. `contoso.onmicrosoft.com`).
2053+
2054+
##### `MICROSOFT_GRAPH_MAILER_CLIENT_ID`
2055+
2056+
The Application (client) ID from the Azure App Registration.
2057+
2058+
##### `MICROSOFT_GRAPH_MAILER_CLIENT_SECRET`
2059+
2060+
The client secret value from the Azure App Registration.
2061+
2062+
##### `MICROSOFT_GRAPH_MAILER_AZURE_AD_ENDPOINT`
2063+
2064+
Azure AD authority endpoint used to obtain an access token. Defaults to `https://login.microsoftonline.com`. Override for sovereign clouds (e.g. `https://login.microsoftonline.us` for Azure Government).
2065+
2066+
##### `MICROSOFT_GRAPH_MAILER_GRAPH_ENDPOINT`
2067+
2068+
Microsoft Graph API endpoint. Defaults to `https://graph.microsoft.com`. Override for sovereign clouds (e.g. `https://graph.microsoft.us` for Azure Government).
2069+
20222070
##### `IMAP_ENABLED`
20232071

20242072
Enable mail delivery via IMAP. Defaults to `true` if `IMAP_USER` is defined, else defaults to `false`.

assets/runtime/config/gitlabhq/gitlab.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ production: &base
211211
# Whether to expunge (permanently remove) messages from the mailbox when they are deleted after delivery
212212
expunge_deleted: false
213213

214+
#start-microsoft-graph-mailer
215+
## Microsoft Graph Mailer
216+
# Send emails via Microsoft Graph API with OAuth 2.0 client credentials.
217+
microsoft_graph_mailer:
218+
enabled: {{MICROSOFT_GRAPH_MAILER_ENABLED}}
219+
user_id: "{{MICROSOFT_GRAPH_MAILER_USER_ID}}"
220+
tenant: "{{MICROSOFT_GRAPH_MAILER_TENANT}}"
221+
client_id: "{{MICROSOFT_GRAPH_MAILER_CLIENT_ID}}"
222+
client_secret: "{{MICROSOFT_GRAPH_MAILER_CLIENT_SECRET}}"
223+
azure_ad_endpoint: "{{MICROSOFT_GRAPH_MAILER_AZURE_AD_ENDPOINT}}"
224+
graph_endpoint: "{{MICROSOFT_GRAPH_MAILER_GRAPH_ENDPOINT}}"
225+
#end-microsoft-graph-mailer
226+
214227
## Build Artifacts
215228
artifacts:
216229
enabled: {{GITLAB_ARTIFACTS_ENABLED}}

assets/runtime/env-defaults

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,17 @@ if [[ -n ${SMTP_USER} ]]; then
362362
SMTP_AUTHENTICATION=${SMTP_AUTHENTICATION:-login}
363363
fi
364364
SMTP_ENABLED=${SMTP_ENABLED:-false}
365-
GITLAB_EMAIL_ENABLED=${GITLAB_EMAIL_ENABLED:-${SMTP_ENABLED}}
365+
MICROSOFT_GRAPH_MAILER_ENABLED=${MICROSOFT_GRAPH_MAILER_ENABLED:-false}
366+
MICROSOFT_GRAPH_MAILER_USER_ID=${MICROSOFT_GRAPH_MAILER_USER_ID:-}
367+
MICROSOFT_GRAPH_MAILER_TENANT=${MICROSOFT_GRAPH_MAILER_TENANT:-}
368+
MICROSOFT_GRAPH_MAILER_CLIENT_ID=${MICROSOFT_GRAPH_MAILER_CLIENT_ID:-}
369+
MICROSOFT_GRAPH_MAILER_CLIENT_SECRET=${MICROSOFT_GRAPH_MAILER_CLIENT_SECRET:-}
370+
MICROSOFT_GRAPH_MAILER_AZURE_AD_ENDPOINT=${MICROSOFT_GRAPH_MAILER_AZURE_AD_ENDPOINT:-https://login.microsoftonline.com}
371+
MICROSOFT_GRAPH_MAILER_GRAPH_ENDPOINT=${MICROSOFT_GRAPH_MAILER_GRAPH_ENDPOINT:-https://graph.microsoft.com}
372+
if [[ ${SMTP_ENABLED} == true || ${MICROSOFT_GRAPH_MAILER_ENABLED} == true ]]; then
373+
GITLAB_EMAIL_ENABLED=${GITLAB_EMAIL_ENABLED:-true}
374+
fi
375+
GITLAB_EMAIL_ENABLED=${GITLAB_EMAIL_ENABLED:-false}
366376
GITLAB_EMAIL=${GITLAB_EMAIL:-${SMTP_USER}}
367377
GITLAB_EMAIL_REPLY_TO=${GITLAB_EMAIL_REPLY_TO:-${GITLAB_EMAIL}}
368378
GITLAB_EMAIL_SUBJECT_SUFFIX=${GITLAB_EMAIL_SUBJECT_SUFFIX:-}

assets/runtime/functions

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,24 @@ gitlab_configure_mail_delivery() {
473473
fi
474474
}
475475

476+
gitlab_configure_microsoft_graph_mailer() {
477+
if [[ ${MICROSOFT_GRAPH_MAILER_ENABLED} == true ]]; then
478+
echo "Configuring gitlab::microsoft_graph_mailer..."
479+
exec_as_git sed -i "/#start-microsoft-graph-mailer/d" ${GITLAB_CONFIG}
480+
exec_as_git sed -i "/#end-microsoft-graph-mailer/d" ${GITLAB_CONFIG}
481+
update_template ${GITLAB_CONFIG} \
482+
MICROSOFT_GRAPH_MAILER_ENABLED \
483+
MICROSOFT_GRAPH_MAILER_USER_ID \
484+
MICROSOFT_GRAPH_MAILER_TENANT \
485+
MICROSOFT_GRAPH_MAILER_CLIENT_ID \
486+
MICROSOFT_GRAPH_MAILER_CLIENT_SECRET \
487+
MICROSOFT_GRAPH_MAILER_AZURE_AD_ENDPOINT \
488+
MICROSOFT_GRAPH_MAILER_GRAPH_ENDPOINT
489+
else
490+
exec_as_git sed -i "/#start-microsoft-graph-mailer/,/#end-microsoft-graph-mailer/d" ${GITLAB_CONFIG}
491+
fi
492+
}
493+
476494
gitlab_configure_mailroom() {
477495
if [[ ${IMAP_ENABLED} == true ]]; then
478496
echo "Configuring gitlab::incoming_email..."
@@ -2041,6 +2059,7 @@ configure_gitlab() {
20412059
gitlab_configure_mattermost
20422060
gitlab_configure_project_features
20432061
gitlab_configure_mail_delivery
2062+
gitlab_configure_microsoft_graph_mailer
20442063
gitlab_configure_mailroom
20452064
gitlab_configure_oauth
20462065
gitlab_configure_ldap

0 commit comments

Comments
 (0)