I have used oauth2_imap for Micorosft accounts. The complete instructions can be found here.

https://imapsync.lamiral.info/oauth2/oauth2_imap/README_oauth2.txt

I entered the additional data required for retrieval in the Mailcow web interface. I also created a new cron job that renews the token(s) every 30 minutes. The retrieval of emails now works.

### In a short summary, this is how I proceeded:

Download the file “oauth2_imap.zip” from https://imapsync.lamiral.info/oauth2/

After unpacking the ZIP file, I ran a first test under Windows with the command

oauht2_imap.exe <mail address>

made. This opens a Microsoft login page in the browser. After logging in with the user data of the mail address, you are asked whether you want to give access to the Thunderbird app (the script identifies itself as such). If you confirm this, the first token is generated and saved. This must be done once for each e-mail address.

In Linux, I have created my Mailcow config files in/opt/mailcow-dockerized and all further details refer to this directory.

In the directory /opt/mailcow-dockerized/data/conf/dovecot/ I have unpacked the ZIP file oauth2_imap.zip again. I then copied the opposing token files (in the directory of the same name) from the Windows computer to the Linux computer in the same folder.

In “Edit Sync Jobs” I entered the following additional parameter under Custom Parameters

--oauthaccesstoken1=/etc/dovecot/oauth2_imap/tokens/oauth2_tokens_real-mailadress.txt

(The specified path must be accessible within the container and is therefore written as such. It can be accessed externally under/opt/mailcow-dockerized/data/conf/dovecot/)

Create a Cron.sh in the oauth2_imap directory with the following content:

#!/bin/bash
# Renewal of the token
cd /opt/mailcow-dockerized/data/conf/dovecot/oauth2_imap/
#./oauth2_imap real-mailaddress
./oauth2_imap real-mailadress1 >/dev/null 2>&1
./oauth2_imap real-mailadress2 >/dev/null 2>&1

chmod +x cron.sh

Then just crontab -e and insert the following content:

*/30 * * * * * /opt/mailcow-dockerized/data/conf/dovecot/oauth2_imap/cron.sh >/dev/null 2>&1

That’s actually it ;-)

  • Ich habe folgende Einstellung:

    outlook.office365.com
    993
    vorname.nachname@outlook.com
    Passwort
    SSL

    –oauthaccessthoken1=/etc/dovecot/oauth2_tokens/tokens/Name des tokens.txt

    Dabei ist der Pfad ab /etc/dovecot/ an den eigenen Pfad anzupassen. Bitte Groß+Kleinschreibung beachten.

Have something to say?

Join the community by quickly registering to participate in this discussion. We'd like to see you joining our great moo-community!

Hallo Roswitina!

Danke für deine Anleitung.

Bei mir steht übrigens zwischen /opt und mailcow-dockerized noch ein /containers/ dazwischen. War dann auch kein Problem.

In meinem Fall haben sehr viele Perl-Files (libhttp-message-perl, libhttp-message-perl, libjson-perl, libwww-perl, Mail::IMAPClient, libemail-address-perl, libnet-dns-perl) gefehlt. Die habe ich nachinstallieren können, bis dann der Skript oauth2_imap gestartet werden konnte. Nun sehe ich auch in meinem Unix-System, dass die Tokens aktualisiert werden.

Du hast übrigens einen Fehler im Crontab - ein Sternzeichen zu viel ;-)
der crontab kann sonst nicht gespeichert werden.

Ich kann mich trotzdem nicht mit Outlook verbinden. Der sagt immer etwas von Credentials. Was steht bei deinen Sync-Jobs drinnen?! Das wäre mir eine eventuelle Hilfe, da ich schon einige leider erfolglose Versuche unternommen habe.

Danke!

Das mit den Perl-Files stimmt. Habe ich leider unterschlagen. Der Mailcow Server steht übrigens bei mir zu Hause als Proxmox LXC und ist von extern nicht erreichbar

Ich selbst nutze mailcow momentan nur zum Sammeln meiner Mails von verschiedenen Accounts. Dazu habe ich für imspsync die Token für den Zugriff bei Microsoft benötigt.

Wie meinst dass das mit dem Zugriff über Outlook? Outlook kann selber oauth2.

Alles klar.
Ich habe meinen Server so eingerichtet, dass er Mails von verschiedenen Accounts sammelt. Dieser ist auch von außen erreichbar, um die Mails am Handy usw. abzurufen.

Einige Accounts funktionieren noch, aber seit 26.9. hat outlook.com seinen Zugriff verschärft.

Ich habe im Job outlook.office365.com mit dem Mail und Passwort drinnen. SSL nach wie vor drinnen (auch mit Plain / Starttls probiert). Deine Zeile mit oauthaccess… ist in eigene Parameter drinnen.

Mailcow sagt, dass der Zugriff unauthorized ist.
Error login on [outlook.office365.com] with user [xxxxxx@outlook.com] auth [XOAUTH2 accesstoken]: 2 NO AUTHENTICATE failed.
The most frequent error is ERR_AUTHENTICATION_FAILURE_USER1. Check the credentials for xxxxxx@outlook.com.

Hast du da diesbezüglich Erfahrungen?

Ich habe folgende Einstellung:

outlook.office365.com
993
vorname.nachname@outlook.com
Passwort
SSL

–oauthaccessthoken1=/etc/dovecot/oauth2_tokens/tokens/Name des tokens.txt

Dabei ist der Pfad ab /etc/dovecot/ an den eigenen Pfad anzupassen. Bitte Groß+Kleinschreibung beachten.

Danke dir!
Genau das selbe habe ich auch. Es klappte nicht.
Ich werde weiter probieren.

Hast du imapsync auch eingebunden oder nur dieses oauth hergenommen?

Welche Version von Mailcow hast du?

Ich habe derzeit die aktuelle Version: 2024-08a
Ich habe nur die oauth2_imap.zip verwendet.

Ich könnte mir vorstellen, da du eventuell andere Pfade verwendest, das hier das Problem liegt. Schau doch mal im Dovecot Image nach, ob er das tokens file sieht und lesen kann.

Ich würde dabei so vorgehen:

docker ps gibt alle ContainerID aus (wichtig für dich ist –> c136axxxxxxxxx mailcow/dovecot:2.1
docker exec -it c136axxxxx bash hier die ContainerID eingeben. Danach bist du im Container
cd /etc/dovecot/
ls -al zeigt dir den Inhalt des Verzeichnisses

Hier sollte das von dir kopierte verzeichnis “oauth2_imap” mit dem Ordner “tokens” und darin betreffende Datei sein. Das wäre dann auch der Pfad, den du in “–oauthaccesstoken1=/etc/dovecot……” (ohne Lehrzeichen) einfügend must.

Auszug aus meiner verwendeten docker-compose.yml
In der 2ten Zeile nach Volumes sieht man die von mir verwendeten Verzeichnisse

vor dem Doppelpunkt ist das lokale Verzeichnis
nach dem Doppelpunkt ist das im Container verwendete Verzeichnis

dovecot-mailcow:
      image: mailcow/dovecot:2.1
      depends_on:
        - mysql-mailcow
        - netfilter-mailcow
      dns:
        - ${IPV4_NETWORK:-172.22.1}.254
      cap_add:
        - NET_BIND_SERVICE
      volumes:
        - ./data/hooks/dovecot:/hooks:Z
        - ./data/conf/dovecot:/etc/dovecot:z
        - ./data/assets/ssl:/etc/ssl/mail/:ro,z
        - ./data/conf/sogo/:/etc/sogo/:z
        - ./data/conf/phpfpm/sogo-sso/:/etc/phpfpm/:z
        - vmail-vol-1:/var/vmail
        - vmail-index-vol-1:/var/vmail_index
        - crypt-vol-1:/mail_crypt/
        - ./data/conf/rspamd/custom/:/etc/rspamd/custom:z
        - ./data/assets/templates:/templates:z
        - rspamd-vol-1:/var/lib/rspamd
        - mysql-socket-vol-1:/var/run/mysqld/

Die Pfade sind an sich alle in Ordnung - ich habe auch die Volumes richtig

xxxxxx:/# ls -la /etc/dovecot/oauth2_imap/
total 100
drwxrwxr-x 6 root root 4096 Oct 10 18:18 .
drwxr-xr-x 7 root root 4096 Oct 10 02:14 ..
drwxrwxr-x 2 root root 4096 Aug 25 17:57 RCS
-rwxr--r-- 1 root root 8933 Aug 20 20:25 README_oauth2.txt
drwxrwxr-x 2 root root 4096 Jun 3 11:52 cert
-rwxr-xr-x 1 root root 266 Oct 10 00:59 cron.sh
-rw-rw-r-- 1 root root 1310 Jun 3 11:53 localhost.crt
-rw-rw-r-- 1 root root 1675 Jun 3 11:53 localhost.key
-rwxr-xr-x 1 root root 2284 Jun 6 13:37 localhost_CA_cert
-rwxr-xr-x 1 root root 48547 Aug 20 20:26 oauth2_imap
drwxrwxr-x 2 root root 4096 Jun 3 15:21 sundry
drwxrwxr-x 2 root root 4096 Oct 8 17:00 tokens

xxxxxx:/# ls -la /etc/dovecot/oauth2_imap/tokens/
total 16
drwxrwxr-x 2 root root 4096 Oct 8 17:00 .
drwxrwxr-x 6 root root 4096 Oct 10 18:18 ..
-rwx------ 1 root root 1771 Oct 10 00:59 oauth2_tokens_xxxxx@outlook.com.txt
-rwx------ 1 root root 1787 Oct 10 01:27 oauth2_tokens_xxxxx@outlook.com.txt

Da sehe ich, dass der Skript nicht greift bzw. nicht aktualisiert werden kann - bin noch am Suchen. Die cron.sh liegt auch herinnen im Docker - etwas passt nicht. ich suche weiter

Can't locate HTTP/Daemon.pm in @INC (you may need to install the HTTP::Daemon module) (@INC entries checked: /usr/local/lib/perl5/site_perl /usr/local/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl) at ./oauth2_imap line 16.
ich vermute stark, dass ich die perl-skripte im Docker installieren muss.

Cron läuft eigentlich außerhalb des Dockers. Wie ist es bei dir?

Läuft beim mir auch im LXC.
Die Zugriffsrechte passen?

Alles war richtig…
Nur habe ich die cron.sh direkt im BASH ausgeführt. Es war keine Fehlermeldung ersichtlich bisher.
Bis zur Fehlermeldung, die ich gestern aufs Fenster geknallt bekommen habe - libhttp-daemon-ssl-perl nachinstalliert, im Linux ausgeführt, die Links in der Ausgabe kopiert und noch einmal mit Passwort angemeldet und voila, es funktioniert.

Danke jedenfalls noch einmal für deine tatkräftige Unterstützung!

Perfekt.

I would like to do this with my gmail account to get my gmail moved to my mailcow server and quit using gmail.
Do you know if I can apply these instructions to gmail?

Hey Roswitina - kannst du auch ebenfalls NICHT über Outlook-SMTP schicken? oder doch?

5 months later

I cant read postings 14-17!!! It is only displayed up to posting 13.

No one is typing