This is an old revision of the document!
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
Convert the 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:
#! /bin/sh ### BEGIN INIT INFO # Provides: davmail # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: DavMail Exchange gatway # Description: A gateway between Microsoft Exchange and open protocols. ### END INIT INFO # Author: Jesse TeKrony <jesse ~at~ jtekrony ~dot~ com> PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="Davmail Exchange gateway" NAME=davmail CONFIG=/etc/davmail.properties DAEMON=/usr/bin/$NAME DAEMON_ARGS="$CONFIG" PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME LOGFILE=/var/log/davmail.log # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present [ -r /etc/default/$NAME ] && . /etc/default/$NAME # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions . /lib/lsb/init-functions # # Function that starts the daemon/service # do_start() { start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ || return 1 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ $DAEMON_ARGS >> $LOGFILE 2>&1 & [ $? != 0 ] && return 2 echo $! > $PIDFILE exit 0 } # # Function that stops the daemon/service # do_stop() { start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE RETVAL="$?" [ "$RETVAL" = 2 ] && return 2. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON [ "$?" = 2 ] && return 2 rm -f $PIDFILE return "$RETVAL" } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; status) status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? ;; restart|force-reload) log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|status|restart| force-reload}" >&2 exit 3 ;; esac
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. 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.
You will get warnings from your E-mail clients because you are using a self-signed certificate. It is safe to accept the certificate in this case, because you are the one who created it.
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!
Ref: Original by Jesse TeKrony https://www.digitalocean.com/community/tutorials/how-to-setup-a-davmail-exchange-gateway-on-a-debian-7-vps
Discussion