Skip to content

Commit 1e3b620

Browse files
authored
Merge pull request #3240 from fracaron/feature/microsoft-graph-mailer
Add Microsoft Graph Mailer support
2 parents d09e2a4 + 14a0008 commit 1e3b620

4 files changed

Lines changed: 97 additions & 1 deletion

File tree

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [External Redis Server](#external-redis-server)
2424
- [Linking to Redis Container](#linking-to-redis-container)
2525
- [Mail](#mail)
26+
- [Microsoft Graph Mailer](#microsoft-graph-mailer)
2627
- [Reply by email](#reply-by-email)
2728
- [SSL](#ssl)
2829
- [Generation of a Self Signed Certificate](#generation-of-a-self-signed-certificate)
@@ -437,6 +438,26 @@ docker run --name gitlab -d \
437438

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

441+
##### Microsoft Graph Mailer
442+
443+
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.
444+
445+
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:
446+
447+
```bash
448+
docker run --name gitlab -d \
449+
--env 'MICROSOFT_GRAPH_MAILER_ENABLED=true' \
450+
--env 'MICROSOFT_GRAPH_MAILER_USER_ID=00000000-0000-0000-0000-000000000000' \
451+
--env 'MICROSOFT_GRAPH_MAILER_TENANT=contoso.onmicrosoft.com' \
452+
--env 'MICROSOFT_GRAPH_MAILER_CLIENT_ID=11111111-1111-1111-1111-111111111111' \
453+
--env 'MICROSOFT_GRAPH_MAILER_CLIENT_SECRET=YOUR_CLIENT_SECRET' \
454+
--env 'GITLAB_EMAIL=sender@contoso.com' \
455+
--volume /srv/docker/gitlab/gitlab:/home/git/data \
456+
sameersbn/gitlab:18.11.0
457+
```
458+
459+
`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.
460+
440461
##### Reply by email
441462

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

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

2043+
##### `MICROSOFT_GRAPH_MAILER_ENABLED`
2044+
2045+
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.
2046+
2047+
##### `MICROSOFT_GRAPH_MAILER_USER_ID`
2048+
2049+
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.
2050+
2051+
##### `MICROSOFT_GRAPH_MAILER_TENANT`
2052+
2053+
The Azure AD tenant ID (GUID) or tenant domain (e.g. `contoso.onmicrosoft.com`).
2054+
2055+
##### `MICROSOFT_GRAPH_MAILER_CLIENT_ID`
2056+
2057+
The Application (client) ID from the Azure App Registration.
2058+
2059+
##### `MICROSOFT_GRAPH_MAILER_CLIENT_SECRET`
2060+
2061+
The client secret value from the Azure App Registration.
2062+
2063+
##### `MICROSOFT_GRAPH_MAILER_AZURE_AD_ENDPOINT`
2064+
2065+
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).
2066+
2067+
##### `MICROSOFT_GRAPH_MAILER_GRAPH_ENDPOINT`
2068+
2069+
Microsoft Graph API endpoint. Defaults to `https://graph.microsoft.com`. Override for sovereign clouds (e.g. `https://graph.microsoft.us` for Azure Government).
2070+
20222071
##### `IMAP_ENABLED`
20232072

20242073
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,24 @@ production: &base
170170
## Disable jQuery and CSS animations
171171
# disable_animations: true
172172

173+
#start-microsoft-graph-mailer
174+
# Allows delivery of emails using Microsoft Graph API with OAuth 2.0 client credentials flow.
175+
microsoft_graph_mailer:
176+
enabled: {{MICROSOFT_GRAPH_MAILER_ENABLED}}
177+
# The unique identifier for the user. To use Microsoft Graph on behalf of the user.
178+
user_id: "{{MICROSOFT_GRAPH_MAILER_USER_ID}}"
179+
# The directory tenant the application plans to operate against, in GUID or domain-name format.
180+
tenant: "{{MICROSOFT_GRAPH_MAILER_TENANT}}"
181+
# The application ID that's assigned to your app. You can find this information in the portal where you registered your app.
182+
client_id: "{{MICROSOFT_GRAPH_MAILER_CLIENT_ID}}"
183+
# The client secret that you generated for your app in the app registration portal.
184+
client_secret: "{{MICROSOFT_GRAPH_MAILER_CLIENT_SECRET}}"
185+
# Defaults to "https://login.microsoftonline.com".
186+
azure_ad_endpoint: "{{MICROSOFT_GRAPH_MAILER_AZURE_AD_ENDPOINT}}"
187+
# Defaults to "https://graph.microsoft.com".
188+
graph_endpoint: "{{MICROSOFT_GRAPH_MAILER_GRAPH_ENDPOINT}}"
189+
#end-microsoft-graph-mailer
190+
173191
## Reply by email
174192
# Allow users to comment on issues and merge requests by replying to notification emails.
175193
# For documentation on how to set this up, see http://doc.gitlab.com/ce/administration/reply_by_email.html

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)