Setting up Mutt and IMAP for email through Exchange EWS

One of the nice things about working for Canonical these past many years was having an entirely Linux-based infrastructure. For the most part I never needed to worry about the existance of Windows.

Yet, having now joined a company, that – like most of the modern world – is fundamentally Microsoft infrastructured, I find myself needing to interface with Exchange to get and send my email.

At first I took the easy route of using Outlook webmail in firefox. This wasn’t total frustration, I actually kinda liked the conversation grouping feature. But inevitably the frustrations eventually hit a breaking point!

I assumed setting up mutt with Exchange would be a well trod path on the Internet and I could just paint-by-numbers my way through. No such luck. So, in hopes of saving others some work of piecing things together from man pages, random forum posts, and plain trial and error, here’s my guide for getting this all set up.

Certain Linux-based mail clients like Thunderbird and Evolution are able to speak directly with Exchange using EWS. However, there are many other Linux email and calendaring clients available that you may want to use, but that don’t support Exchange EWS. For instance, you may wish to use a console-based mail client such as mutt.

Fortunately, you can set up DavMail as an intermediary gateway. DavMail interfaces with the Exchange server, presenting it as a standards-compliant POP/IMAP/SMTP/Caldav/Carddav/LDAP service. In other words, you use IMAP or POP to browse or retrieve emails, SMTP to send email, LDAP to look up addresses, Caldav for calendaring, and Carddav for personal contacts.

Setting up the DavMail server

The DavMail package can be downloaded from At the time of this writing it appears to not exist in the Ubuntu archive, however a .deb file suitable for Debian and Ubuntu is available from the above link. For other Linux distributions you’ll need to use the standard tarball package and manually install Java.

  # Install on Ubuntu
  sudo apt-get install libswt-gtk-3-java   # Or other java as desired
  sudo dpkg -i davmail_4.3.3-2146-1_all.deb

You can then launch DavMail via the Applications/Internet menu.

DavMail does not store any credentials, it merely needs to know the name and path of the Exchange server to use. The first time you launch DavMail, a configuration dialog will appear. Only one parameter needs changed:

  URL OWA (Exchange):

The rest of the settings can be left at defaults. See the DavMail Tutorial for info about the rest of the settings or if you run into problems. Note that logging information is written to ~/davmail.log.

Finally, set up DavMail to start up on session login. For example:

  echo "davmail &" >> ~/.gnomerc

I’d never heard of DavMail before, but it’s been quite solid so far.

Setting up msmtp SMTP client

Sendmail is the de facto standard for SMTP, but is a bit overkill if you’re just setting up a single user local email environment. msmtp is simpler to configure and adequate for single user email needs.

  sudo apt-get install msmtp
  touch ~/.msmtprc ~/.msmtp.log
  chmod 600 ~/.msmtprc ~/.msmtp.log

Since the IMAP server is on localhost, the msmtp configuration is quite basic:

  # ~/.msmtprc
  logfile ~/.msmtp.log

  account default
  host localhost
  port 1025
  protocol smtp
  auth AUTH
  user DOMAIN\f.lastname
  password  PASSWORD

Here, PASSWORD is your own password, DOMAIN is going to be something specific to your company, and for AUTH it’ll depend on how you want to have things set up. See msmtp authentication for options.

Setting up mutt for email

If you’ve used mutt before, you’ll already be familiar with its myriad configuration options. If you haven’t, then this section isn’t for you!

So, skipping over installation and basic mutt configuration, here’s how to configure mutt to use IMAP. This keeps the emails and folders on the remote server and uses the local DavMail service for sending and receiving emails.

  # ~/.muttrc
  set spoolfile="imap://f.lastname:PASSWORD@"
  set folder="imap://f.lastname:PASSWORD@"
  set from=""
  set realname='Firstname Lastname'
  set trash="imap://f.lastname:PASSWORD@"
  set imap_user=""
  set imap_pass="PASSWORD"
  set imap_keepalive=900   # Set lower if connection times out
  set header_cache=~/.mutt/cache/headers
  set message_cachedir=~/.mutt/cache/bodies

  set sendmail="/usr/bin/msmtp"
  my_hdr From: "Firstname Lastname"

Setting up git

You can direct git to send patches through SMTP via the DavMail server.

  # ~/.gitconfig
        name = Firstname Lastname
        email =

        smtpserver = localhost
        supresscc = self
        from = Firstname Lastname 
        smtppass = PASSWORD
        smtpserverport = 1025
        smtpuser = f.lastname
        confirm = auto
	chainreplyto = true

1 Responses to Setting up Mutt and IMAP for email through Exchange EWS

  1. Guillaume Laferriere says:

    Thanks for this excellent tutorial.

    I was able to get Mutt to read my owa mails from work. I struggled a bit to get pass the fetching phase when starting Mutt. It kept on refetching from message 1 without writing the header cache.

    I had to do 2 small changes to

    # Don't fetch all the emails... only the newest 500. # I was reading from a 12000 mails inbox and could't get past the fetching pass. davmail.folderSizeLimit=500

    # Ran into a problem when sending mails # ErrorSendAsDenied ERROR davmail - ErrorSendAsDenied The user account which was used to submit this request does not have the right to send mail on behalf of the specified sending account. # davmail.smtpStripFrom=true

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>