Skip to content

Instantly share code, notes, and snippets.

@Raymo111
Last active January 23, 2022 23:37
Show Gist options
  • Save Raymo111/737cbd1d94312afe690cccae91c40dc9 to your computer and use it in GitHub Desktop.
Save Raymo111/737cbd1d94312afe690cccae91c40dc9 to your computer and use it in GitHub Desktop.
How to connect to UWaterloo's new email system via any mail client

How to connect to UWaterloo's new email system via any mail client

By Raymond Li (Raymo111), July 1st, 2020 (Happy Canada Day!)

Last updated 12 Sept 2021
Credits to PixlOne for O365Interactive mode and headless Davmail

Step 1: Get Davmail.

  • I'm on Arch Linux, so I installed it from the AUR.

Step 2: Launch and configure Davmail.

  • Use O365Interactive for Protocol, and uncheck Local POP port, Caldav HTTP port, and Local LDAP port. Keep everything else as the default, and hit save.

Step 3: Setup your mail client.

  • I'm using Mailspring, which I believe is the best mail client I can get for free. [Not Sponsored]
  • Use manual config (IMAP/SMTP) to setup the account.
  • Use <your WatIAM username>@uwaterloo.ca as your username and your WatIAM password.
  • Use localhost as the server.
  • Use the ports set in Davmail (1143 for IMAP and 1025 for SMTP by default).
  • Set any authentication to None.
  • The first time you attempt to connect, you'll get a Davmail popup and the UWaterloo adfs page will open. Login with your credentials, and paste the link you reach at the end into the Davmail prompt.

Step 4: Run it as a headless service.

  • Success! Your mail should now work. Davmail basically acts as an interpreter between the O365/Exchange network and IMAP/SMTP. As such, it must be constantly running to receive/send mail. Go ahead and exit Davmail. Copy the properties from your home directory to /etc with:
sudo cp ~/.davmail.properties /etc/davmail/<your-linux-username>.properties

and change O365Interactive to O365Manual in the config file:

sed -i 's/O365Interactive/O365Manual/g'
  • Add a davmail user:
sudo useradd --system davmail
  • Finally, start and enable the service with:
sudo systemctl enable --now davmail@<your-linux-username>

That's it! Note: Always test and verify via the webapp before relying on any setup!

@obaranek
Copy link

thank you so much for this, i have been trying to find a way to make mailspring work. I am getting a syncing error towards the end of step 3.
I was wonderring if you know how to fix it?

@Raymo111
Copy link
Author

@obaranek Can you post a screenshot of your syncing error and a Mailspring log?

@obaranek
Copy link

@obaranek
Copy link

@Raymo111 where does mailspring store its logs?

@Raymo111
Copy link
Author

Hmm... not sure. Do you have davmail running? What's the output of this?

sudo systemctl status davmail@<your-linux-username>

@obaranek
Copy link

davmail@obaranek.service - DavMail for obaranek
Loaded: loaded (/usr/lib/systemd/system/davmail@.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-02-22 12:14:36 EST; 1h 14min ago
Main PID: 250785 (java)
Tasks: 26 (limit: 18757)
Memory: 39.6M
CGroup: /system.slice/system-davmail.slice/davmail@obaranek.service
└─250785 /bin/java -jar /usr/share/java/davmail/davmail.jar /etc/davmail/obaranek.properties

Feb 22 12:14:36 arch davmail[250785]: 2021-02-22 12:14:36,325 ERROR [main] davmail - Unable to create log file directory
Feb 22 12:14:36 arch davmail[250785]: 2021-02-22 12:14:36,325 ERROR [main] davmail - Unable to set log file path
Feb 22 12:14:36 arch davmail[250785]: 2021-02-22 12:14:36,354 DEBUG [main] davmail.DavGateway - Headless mode, do not create GUI
Feb 22 12:14:36 arch davmail[250785]: 2021-02-22 12:14:36,355 ERROR [main] davmail - Unable to set log file path
Feb 22 12:14:36 arch davmail[250785]: 2021-02-22 12:14:36,355 DEBUG [main] davmail.DavGateway - Start DavMail in server mode
Feb 22 12:14:36 arch davmail[250785]: 2021-02-22 12:14:36,384 INFO [main] davmail - DavMail Gateway 5.5.1-3299 listening on POP port 1110 CALDAV port 1080 LDAP port 1389
Feb 22 12:14:36 arch davmail[250785]: 2021-02-22 12:14:36,385 ERROR [main] davmail - Unable to bind server socket for SMTP on port 1025: port not allowed or in use by another process
Feb 22 12:14:36 arch davmail[250785]: Unable to bind server socket for IMAP on port 1143: port not allowed or in use by another process
Feb 22 12:14:36 arch davmail[250785]: 2021-02-22 12:14:36,436 DEBUG [CheckRelease] davmail.http.HttpClientAdapter - GET http://davmail.sourceforge.net/version.txt
Feb 22 12:14:36 arch davmail[250785]: 2021-02-22 12:14:36,686 DEBUG [CheckRelease] davmail.DavGateway - DavMail released version: 5.5.1-3299

@Raymo111
Copy link
Author

Raymo111 commented Feb 22, 2021

It seems that davmail doesn't have the perms to really do anything (i.e. create log file or use your ports). Did you follow all the steps I listed?

@obaranek
Copy link

i did, these are my davmail settings
image

@obaranek
Copy link

this is the mailspring log

image

@Raymo111
Copy link
Author

What do you get when you run groups davmail?

@obaranek
Copy link

i get "davmail"

@Raymo111
Copy link
Author

Try rebooting your system for davmail user perms to propagate, and then run the status command again after reboot to see if the same error persists.

@obaranek
Copy link

after rebooting, this is my ouput

davmail@obaranek.service - DavMail for obaranek
Loaded: loaded (/usr/lib/systemd/system/davmail@.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-02-22 13:51:11 EST; 56s ago
Main PID: 2291 (java)
Tasks: 28 (limit: 18757)
Memory: 66.5M
CGroup: /system.slice/system-davmail.slice/davmail@obaranek.service
└─2291 /bin/java -jar /usr/share/java/davmail/davmail.jar /etc/davmail/obaranek.properties

Feb 22 13:51:11 arch davmail[2291]: 2021-02-22 13:51:11,993 ERROR [main] davmail - Unable to create log file directory
Feb 22 13:51:11 arch davmail[2291]: 2021-02-22 13:51:11,993 ERROR [main] davmail - Unable to set log file path
Feb 22 13:51:11 arch davmail[2291]: 2021-02-22 13:51:11,993 ERROR [main] davmail - Unable to create log file directory
Feb 22 13:51:11 arch davmail[2291]: 2021-02-22 13:51:11,993 ERROR [main] davmail - Unable to set log file path
Feb 22 13:51:12 arch davmail[2291]: 2021-02-22 13:51:12,061 DEBUG [main] davmail.DavGateway - Headless mode, do not create GUI
Feb 22 13:51:12 arch davmail[2291]: 2021-02-22 13:51:12,063 ERROR [main] davmail - Unable to set log file path
Feb 22 13:51:12 arch davmail[2291]: 2021-02-22 13:51:12,063 DEBUG [main] davmail.DavGateway - Start DavMail in server mode
Feb 22 13:51:12 arch davmail[2291]: 2021-02-22 13:51:12,123 INFO [main] davmail - DavMail Gateway 5.5.1-3299 listening on SMTP port 1025 POP port 1110 IMAP port 1143 CALDAV port 1080 LDAP port 1389
Feb 22 13:51:12 arch davmail[2291]: 2021-02-22 13:51:12,232 DEBUG [CheckRelease] davmail.http.HttpClientAdapter - GET http://davmail.sourceforge.net/version.txt
Feb 22 13:51:12 arch davmail[2291]: 2021-02-22 13:51:12,256 DEBUG [CheckRelease] davmail - Unable to get released version

@obaranek
Copy link

this is my output after rebooting
image

mailspring doesn't seem to be syncing but there is no error

this it what i see in davmail

image

@Raymo111
Copy link
Author

Hmm... not sure. Seems like davmail is disconnecting after a successful connection, but I have no idea why. Sorry mate.

@obaranek
Copy link

no worries, thanks for your help!

@Raymo111
Copy link
Author

❤️
Huh seems like Gist doesn't have reactions.

@martellato
Copy link

Hey, thanks a bunch for this! I got it working on Thunderbird, but I ended up using the EWS protocol instead of the O365Interactive. For some reason, it failed to authenticate that way. The window would pop up but go nowhere after the certificate warning. Maybe that will help @obaranek too!

@kishvanchee
Copy link

kishvanchee commented Aug 19, 2021

Thank you, this was really helpful. For anyone who might be doing this with Arch Linux, I have added the service to /etc/systemd/system/davmail.service

[Unit]
Description=DavMail Exchange Gateway
After=network.target
Requires=network-online.target

[Service]
Type=simple
RemainAfterExit=no
ExecStart=/usr/bin/davmail /home/kishore/.davmail.properties
ExecStop=killall davmail

[Install]
WantedBy=multi-user.target

and then sudo systemctl enable davmail --now. Hope it helps.

Thank you for the instructions.

@Raymo111
Copy link
Author

Thank you, this was really helpful. For anyone who might be doing this with Arch Linux, I have added the service to /etc/systemd/system/davmail.service

[Unit]
Description=DavMail Exchange Gateway
After=network.target
Requires=network-online.target

[Service]
Type=simple
RemainAfterExit=no
ExecStart=/usr/bin/davmail /home/kishore/.davmail.properties
ExecStop=killall davmail

[Install]
WantedBy=multi-user.target

and then sudo systemctl enable davmail --now. Hope it helps.

Thank you for the instructions.

No worries, I cleaned up your comment a bit, it should work like that too yes.

@ABrambleNinja
Copy link

Thanks for putting this guide together! The EWS authentication stopped working for me recently, I believe, but the Office365Interactive one worked just fine once I figured out this weird issue:

@martellato are you using Wayland by any chance? If so, I found a weird issue with the web browser opening up, see here for more details: https://sourceforge.net/p/davmail/support-requests/373/

@martellato
Copy link

@ABrambleNinja Same! I'm on X11; for me, the pop-up would appear but with a certificate error. Once I clicked on the button to acknowledge and continue, the window would close and do nothing. When EWS stopped working, I could switch to O365Interactive, and it worked just fine this time.

Do you guys know how to set up LDAP and calendar events?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment