Mail loop with Microsoft Graph for outgoing and incoming mail enabled with the same mailbox
Summary
When using microsoft graph method for incoming and outgoing mails with the same user/mailbox gitlab will reply on self generated emails and will be then in an infinite loop of replying to its own emails.
Steps to reproduce
-
Install a self hosted GitLab (in this case from Azure marketplace https://azuremarketplace.microsoft.com/en-us/marketplace/apps/gitlabinc1586447921813.gitlabee )
-
Enable incoming email (user: gitlab@example.com) as given in https://docs.gitlab.com/ee/administration/incoming_email.html#microsoft-graph
-
Enable outgoing email with the same user before (gitlab@example.com) as given in https://docs.gitlab.com/omnibus/settings/microsoft_graph_mailer.html
-
Send a email from the rails console
Notify.test_email('gitlab+foo@example.com', 'Mail Loop Test', 'Some Body').deliver_now
Delivered mail 662ff66c632ff_45dc2d001438@gitlab.mail (676.0ms)
=> #<Mail::Message:561XXX, Multipart: false, Headers: <Date: Mon, 29 Apr 2024 19:35:08 +0000>, <From: GitLab <gitlab@example.com>>, <Reply-To: GitLab <gitlab@example.com>>, <To: gitlab+foo@example.com>, <Message-ID: <662ff66c632ff_XXXXXX@gitlab.mail>>, <Subject: Mail Loop Test>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
What is the current bug behavior?
Each incoming_email_inbox_options_poll_intervall
(default: 60s) there will be a reply email to the first email. After 3 iterations (>3min) this Mail will look like:
[Rejected] [Rejected] [Rejected] Mail Loop Test
Unfortunately, your email message to GitLab could not be processed.
We couldn't figure out what the email is for. Please create your issue or comment through the web interface.
What is the expected correct behavior?
No Reply to any email with the email header set Auto-Submitted: auto-generated
or X-Auto-Response-Suppress: All
.
Relevant logs and/or screenshots
/var/log/gitlab/gitlab-rails/production.log
:
Delivered mail 2220d45b04eaacf8a7ef1XXXXXXX@gitlab.XXXXXX.com (782.2ms)
Delivered mail 07df5355532a4b7a6272f13XXXX@gitlab.XXXXXX.com (640.8ms)
Delivered mail d6be0dccf279b2214b7d6XXXXXX@gitlab.XXXXXX.com (748.8ms)
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
bitnami@gitlab:~$ sudo gitlab-rake gitlab:env:info System information System: Debian 12 Proxy: no Current User: git Using RVM: no Ruby Version: 3.1.4p223 Gem Version: 3.5.7 Bundler Version:2.5.8 Rake Version: 13.0.6 Redis Version: 7.0.15 Sidekiq Version:7.1.6 Go Version: unknown GitLab information Version: 16.11.1-ee Revision: 5f640bd48cc Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 14.11 URL: https://gitlab.XXXXXX.com HTTP Clone URL: https://gitlab.XXXXXX.com/some-group/some-project.git SSH Clone URL: git@gitlab.XXXXXX.com:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers: azure_activedirectory_v2 GitLab Shell Version: 14.35.0 Repository storages: - default: unix:/var/opt/gitlab/gitaly/gitaly.socket GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Gitaly - default Address: unix:/var/opt/gitlab/gitaly/gitaly.socket - default Version: 16.11.1 - default Git Version: 2.43.2
Results of GitLab application Check
Expand for output related to the GitLab application check
bitnami@gitlab:~$ sudo gitlab-rake gitlab:check SANITIZE=true Checking GitLab subtasks ...Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 14.35.0 ? ... OK (14.35.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes Number of Sidekiq processes (cluster/worker) ... 1/1
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Reply by email is disabled in config/gitlab.yml
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab App ...
Database config exists? ... yes Tables are truncated? ... skipped All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Cable config exists? ... yes Resque config exists? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Systemd unit files or init script exist? ... skipped (omnibus-gitlab has neither init script nor systemd units) Systemd unit files or init script up-to-date? ... skipped (omnibus-gitlab has neither init script nor systemd units) Projects have namespace: ... 47/1 ... yes Redis version >= 6.2.14? ... yes Ruby version >= 3.0.6 ? ... yes (3.1.4) Git user has default SSH configuration? ... yes Active users: ... 4 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x-8.x or OpenSearch version 1.x ... skipped (Advanced Search is disabled) All migrations must be finished before doing a major upgrade ... skipped (Advanced Search is disabled)
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished
Possible fixes
Since I do not have a gitlab dev env running I can only suspect that somehow the filters in:
are not working as expected for mails from microsoft graph. Maybe the header informations are missing when the mails are getting queued: