DavMail Guide - A local alternative to Microsoft Outlook

Even though Outlook/Exchange does great at its job, some prefer to use their own email clients and calendars. This is a guide that aims to help those looking to use their own email client (Thunderbird, mbsync, mu4e, emacs etc) through DavMail.

Image credit: DavMail

Why Switch

For some of us the use who are very well integrated into the Microsoft, Windows or other ecosystems, Outlook can be a significant boost to productivity and usability. This article is not positioned as a means of convincing individuals to switch to a local GNU/Terminal/Thunderbird setup but rather to facilitate those who are already thinking or have switched over but are struggling getting the various authentication protocols with their institution working. To catch up to recent news, Microsoft implemented an OAuth2 protocol into their suite not too long ago and a majority of institutions have made the switch, rendering the plug and play installations of alternative email clients redundant. Now installing involves getting the correct SMTP and IMAP servers, correctly configuring ports and whatnot, which seems like a lot of needless minutiae in just wanting to use a personal mail client.

However, with the use of DavMail, which is an email/calendar exchange gateway, it is possible for theoretically any mail client to be used as a replacement to Outlook. The DavMail server works by communicating directly with the OWA Exchange servers and runs a local SMTP and IMAP port which your email client will listen too. This sounds great, but getting this to work can be a bit messy based on your institution. For the institution I am working with Thunderbird settings used to work correctly until recently, so the switch to DavMail was necessary.

Installation and Prequisites

What you will need for this setup is of course DavMail: please see the installation instructions here or below. There are a number of different ways based on your operating system but I will lightly go over them here:

Windows

  1. Download the exe here
  2. Unzip and run the installation setup.

OPTIONAL: If you want to make use of the terminal then you may have to link the PATH to your environment variables.

Mac

  1. Make sure you have the correct Java installed as described.
  2. Download DavMail
  3. As the official documentation states you may need to disable GateKeeper to get this working.
  4. Run the installer.

Standalone Setup

  1. Download the DavMail version for Linux.
  2. Unzip the download unzip davmail-version.zip
  3. Run ./davmail azul to setup the latest Azul files, and then run ./davmail.

Debian Based

  1. Depending on whether you are using the GUI or command line installation you may need extra packages to be installed:

GUI to get working with the system tray:

sudo apt-get install gnome-shell-extension-top-icons gnome-shell-extension-appindicator gnome-tweak-tool
  1. Download the DavMail version for Linux.
  2. Install the package.
  3. DavMail should now appear as one of your applications.

AUR

Use your aur helper tool and install:

# Choose one of the many aur helpers or build yourself
yay -S davmail
yaourt -S davmail
aur sync davmail

Getting DavMail working

Configuration File

The first thing of this setup is to get the DavMail configuration:

Create a configuration file, you can name it anything since we will pass it as a parameter to our DavMail program. NOTE: This partly follows the setup from the documentation:

######################
# Logging Settings
######################
# Logging information while running and output to /var/log/davmail.log
# Set to warn but feel free to update this to DEBUG if you are facing some issues
log4j.logger.davmail=WARN
log4j.logger.httpclient.wire=WARN
log4j.logger.org.apache.commons.httpclient=WARN
log4j.rootLogger=WARN

######################
# Connection Settings
######################
# Base exchange URL: TODO FILL THIS IN CORRECTLY
davmail.url=https://sydney.edu.au/email

# This exchange method was the only that worked with my institution
davmail.mode=O365Interactive

# We want to run as a server not workstation
davmail.server=true

######################
# Port Settings
######################
# Setup ports, make sure these are not being used by another process
davmail.caldavPort=1080
davmail.imapPort=1143
davmail.ldapPort=1389
davmail.popPort=1110
davmail.smtpPort=1025


######################
# Network Settings
######################
# We need to disable SSL to get this working
davmail.ssl.nosecureimap=false
davmail.ssl.nosecureldap=false
davmail.ssl.nosecurecaldav=false
davmail.ssl.nosecuresmtp=false
davmail.ssl.nosecurepop=false

# We want to keep this alive for large file and message downloads so it doesn't timeout
davmail.enableKeepAlive=true



# We don't need remote connections to DavMail, this may change depending on your setup, if you are running this externally.
davmail.allowRemote=false

######################
# SMTP Settings
######################
# let Exchange save a copy of sent messages in Sent folder
davmail.smtpSaveInSent=true


######################
# IMAP Settings
######################
# Delete messages immediately on IMAP STORE \Deleted flag
davmail.imapAutoExpunge=true
# To enable IDLE support, set a maximum client polling delay in minutes
# Clients using IDLE should poll more frequently than this delay
davmail.imapIdleDelay=
# Always reply to IMAP RFC822.SIZE requests with Exchange approximate message size for performance reasons
davmail.imapAlwaysApproxMsgSize=


######################
# POP settings
######################
# Delete messages on server after 30 days
davmail.keepDelay=30
# Delete messages in server sent folder after 90 days
davmail.sentKeepDelay=90
# Mark retrieved messages read on server
davmail.popMarkReadOnRetr=false

I know there is a lot to parse here but the main things you will need to modify is just davmail.url to your mail url and possibly davmail.mode to another authentication mode if necessary. The mail url could be the default https://outlook.office365.com/EWS/Exchange.asmx or it could be based on your webmail e.g. https://mail.institution.edu this would require some tinkering based on your institution setup. This section is the trickiest part but if this works correctly you will most be smooth sailing for the rest of the guide.

GUI Setup (skip if using configuration file)

For the GUI the general tip is to just translate the above settings in the application. Ports can be left to the defaults, the main items that will need to be configured are the:

  • Exchange Protocol same as davmail.mode
  • OWA Url same as davmail.url
  • and possibly the Client ID and URI under the Encryption tab, if you are using other OWA methods.

Initial Setup of Server

Now when this is completed, the next step is to run DavMail with this given configuration:

./davmail <LOCATION_OF_CONF_FILE>

Depending on your logging setting this should come up with some details regarding the ports. The important part here is to connect to our server and authenticate with the exchange server.

Using the browser

Using your browser visit http://localhost:<IMAP PORT> which will bring up the connection details which you will use to connect as normal to your institution.

Using Curl

Make sure `curl`` is installed for this step. The intuition behind this is we want to connect to the local server and give our details to interactively connect to the exchange server:

curl -v imap://localhost:<IMAP PORT>/ -u <USER>@<MAIL>

Fill in each section accordingly.

Authenticating with the Exchange Server

After proceeding from this step we will have a window that asks for an authentication code. Open the link it provides which will link you to a login to your outlook account.

DavMail Window
Credit - DavMail

NOTE: It is important to note here that some people will face an error here regarding finding the wrong application ID. If so please refer to your IT administrators to get the correct client ID.

Afterwards, you should be linked to a blank page, but don’t worry and close it, this is exactly what we want. In the url you should see something akin to this format:

https://login.microsoftonline.com/common/oauth2/nativeclient?code=<CODE>&session_state=<SESSION_STATE>

What we want to extract from here is the url which should be copied and pasted within the DavMail window that opened previously. NOTE: You can also directly copy the <CODE> section but make sure to leave out the = and & symbols from the start and end of the code respectively, this is not part of the actual key.

Once this is done, if you used curl you should see this message pop up with an authentication:

< A002 OK Authenticated
> A003 LIST "" *

Then below would be a list of the folders within your outlook account e.g. Inbox, Sent etc.

All done, now you can proceed with the setup with your email client. To do so you want to setup the following connections:

ValueDetail
UsernameYour outlook email
IMAP PortOne specified in the config
IMAP Hostlocalhost
IMAP AuthenticationPassword for your account
SMTP PortOne specified in the config
SMTP Hostlocalhost
SMTP AuthenticationPassword for your account

And there you go! You should hopefully be connected here, and you can confirm this either through your chosen client or through the davmail.log file which would show that it is fetching emails:

DEBUG [ImapConnection-1231] davmail.imap.ImapConnection  - Message 221224218 sent approximate size 198925 bytes

However, this process of fetching all your emails may take a while so you can play around with the configuration such that you only retrieve a certain amount of emails rather than the entire collection.

Hope this helped!

Adam Ghanem
Adam Ghanem
M.Phil Student

My research interests include natural language models, text-to-image diffusion, systems and sparsity.