Table of Contents
How To Setup a DavMail Exchange Gateway on a Debian 7 VPS
Introduction
DavMail provides a solution for translating Microsoft Exchange to open protocols like POP, IMAP, SMTP, Caldav, Carddav, and LDAP.
Installation
Davmail requires some extra dependencies to work properly. Install them with apt:
sudo apt-get install default-jre libswt-gtk-3-java libswt-cairo-gtk-3-jni
The DavMail project makes a Debian package available on their website through [SourceForge (http://sourceforge.net/projects/davmail/files/davmail/).
Download the latest Debian package with wget:
wget http://sourceforge.net/projects/davmail/files/davmail/4.4.1/davmail_4.4.1-2225-1_all.deb
Then, install DavMail with dpkg:
sudo dpkg -i davmail_4.4.1-2225-1_all.deb
Basic Configuration
DavMail's configuration file does not exist by default. Create one with your favorite text editor:
sudoedit /etc/davmail.properties
Set DavMail to server mode so it doesn't require X11:
davmail.server=true
Enable remote mode and set the bind address to your servers IP address or set it blank:
davmail.allowRemote=true davmail.bindAddress=
Set davmail.url
to your Outlook Web App/Outlook Web Access URL, which usually ends in /owa
:
davmail.url=https://yourcompany.com/owa
Set your connection mode:
davmail.enableEws=auto
Set your port options:
davmail.imapPort=993 davmail.smtpPort=465 davmail.ldapPort=636 davmail.popPort=995 davmail.caldavPort=8443
Save and close the configuration file.
Create A SSL Certificate
Use the Letsencrypt Certbot to create a certificate.
Configuring SSL
cd to /etc/letsencrypt/live/your-server
and convert the letsencrypt certificates to a p12 file using this script. You must use a PASSWORD on the file!
#!/bin/bash sudo openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -certfile cert.pem -out /etc/ssl/certs/davmail.p12
Add the following configuration options to inform DavMail of the location of the pkcs12 file you just generated and the passphrase you set:
davmail.ssl.keystoreType=PKCS12 davmail.ssl.keystoreFile=/usr/lib/ssl/certs/davmail.p12 davmail.ssl.keyPass=PASSWORD davmail.ssl.keystorePass=PASSWORD
Both davmail.ssl.keyPass
and davmail.ssl.keystorePass
should should have the same value. Save the configuration file.
DavMail is now configured to use your SSL certificate.
Start DavMail
The Debian package we downloaded eariler does not contain an init script, so we must create our own.
You can also try starting davmail using
sudo davmail /etc/davmail.properties
To have a proper startup job is better, of course:
Create a new file with your favorite text editor:
sudo nano /etc/init.d/davmail
Copy and paste the following into the file: davmail
Save and close the file.
Mark the script executable, start the service, and enable it at boot:
sudo chmod +x /etc/init.d/davmail
sudo service davmail start
sudo update-rc.d davmail defaults
Client Configuration
Now that the server is running, you are ready to configure your E-mail clients.
Mail setup
Create a new account, using the “manual” options of your E-mail client. Both the IMAP and SMTP server will be the domain name or IP address of your droplet, depending on what you used for the Common Name on your SSL certificate. The username for IMAP and SMTP will both be your E-mail address without the domain name. Example: Your E-mail is bob@yourcompany.com, so your username is bob. Make sure both IMAP and SMTP are set to use SSL/TLS and not STARTTLS.
Specific instructions for Thunderbird, Mac OSX, and iOS is available at DavMail's website.
You should now be able to send/recieve E-mail using your Microsoft Exchange E-mail account using open technologies!
Calendar setup in Thunderbird
In the thundebird calendar create a new networked calendar
Name: your-company Location: https://your-company.tld:8443/users/your-name@your-company/calendar
LDAP Directory setup in Thunderbird
The following worked for me to connect to an exchange server through davmail.
In the address book set up a new server
Name: your-company Hostname: your-server Base DN: ou=people Port number: 636 Bind DN: your-name@your-company
Ref: Original by Jesse TeKrony https://www.digitalocean.com/community/tutorials/how-to-setup-a-davmail-exchange-gateway-on-a-debian-7-vps
Discussion