<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wazi &#187; Andrew Back</title>
	<atom:link href="http://olex.openlogic.com/wazi/author/andrewback/feed/" rel="self" type="application/rss+xml" />
	<link>http://olex.openlogic.com/wazi</link>
	<description>Open Source Articles, Tutorials and Licensing Information</description>
	<lastBuildDate>Mon, 30 Aug 2010 20:40:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Escaping Microsoft Exchange via Davmail + Fetchmail + Postfix + Courier IMAP</title>
		<link>http://olex.openlogic.com/wazi/2009/escaping-microsoft-exchange-via-davmail-fetchmail-postfix-courier-imap/</link>
		<comments>http://olex.openlogic.com/wazi/2009/escaping-microsoft-exchange-via-davmail-fetchmail-postfix-courier-imap/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 20:32:24 +0000</pubDate>
		<dc:creator>Andrew Back</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Courier IMAP]]></category>
		<category><![CDATA[Davmail]]></category>
		<category><![CDATA[Fetchmail]]></category>
		<category><![CDATA[Postfix]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://olex.openlogic.com/wazi/?p=47663</guid>
		<description><![CDATA[This tutorial explains how to use a recipe of Davmail, Fetchmail, Postfix, and Courier IMAP to interface standards-based e-mail clients with Exchange's Outlook Web Access, and to integrate corporate and non-corporate e-mail accounts into a single inbox that's not buried inside the store of the mail user agent.]]></description>
			<content:encoded><![CDATA[<div style='padding:10px;border:1px solid;margin-bottom:20px;'>This article, <a href='http://olex.openlogic.com/wazi/2009/escaping-microsoft-exchange-via-davmail-fetchmail-postfix-courier-imap/'>Escaping Microsoft Exchange via Davmail + Fetchmail + Postfix + Courier IMAP</a>, originally appeared on <a
      href='http://olex.openlogic.com/wazi'>Wazi</a>, a free source for news, information, and articles on open source software.</div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Folex.openlogic.com%2Fwazi%2F2009%2Fescaping-microsoft-exchange-via-davmail-fetchmail-postfix-courier-imap%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Folex.openlogic.com%2Fwazi%2F2009%2Fescaping-microsoft-exchange-via-davmail-fetchmail-postfix-courier-imap%2F&amp;source=OpenLogic&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Many enterprises use Microsoft Exchange for corporate e-mail, and there is frequently no avoiding its use regardless of where you might sit in the organization or the freedom afforded to you in terms of desktop configuration. Whilst Exchange has the capability to provide an IMAP and/or POP service these are frequently disabled, leaving Outlook Web Access (OWA) as the only remaining hope for users of non-Microsoft mail user agents (MUAs). This tutorial explains how to use a recipe of <a href="https://olex.openlogic.com/packages/Davmail" target="_blank">Davmail</a> + <a href="https://olex.openlogic.com/packages/fetchmail" target="_blank">Fetchmail</a> + <a href="https://olex.openlogic.com/packages/postfix" target="_blank">Postfix</a> + <a href="https://olex.openlogic.com/packages/courier-imap" target="_blank">Courier IMAP</a> to interface standards-based e-mail clients with Exchange&#8217;s OWA, and to integrate corporate and non-corporate e-mail accounts into a single inbox and one that is not buried inside the store of the MUA.</p>
<h2>Before You Start</h2>
<p>This particular configuration is perhaps best suited to a more advanced desktop configuration, else as the basis for a server-based resource where you may have multiple desktops and want to synchronize mail across devices.</p>
<p>If you want the quickest and simplest route to getting mail from OWA into your MUA of choice, and are fine with it being pulled down into the local folders of a MUA, you might be better off using Davmail in its desktop configuration and without the complexity of Postfix + Fetchmail + Courier IMAP.</p>
<p>This tutorial assumes that:</p>
<ul>
<li>You have the OWA service configured on your Exchange server, e.g. https://mail.acme.com/exchange/</li>
<li>You have a Gmail account with POP enabled (this tutorial could be easily adapted to other service providers)</li>
<li>You are running Ubuntu GNU/Linux. However, there should be few differences if you are running Debian, and it should be easy enough to adapt this configuration to accommodate RPM-based distributions</li>
<li>You are capable of appropriately securing services, e.g. managing firewall configuration</li>
</ul>
<h2>Meat &amp; Potatoes</h2>
<p>Note: this tutorial uses acme.com as the example corporate mail domain (OWA) and Gmail as the non-corporate mail service. You could just as easily have multiple Exchange accounts and/or standards-based e-mail accounts.</p>
<h3>Install Packages</h3>
<p><a href="http://fetchmail.berlios.de/" target="_blank">Fetchmail</a>, <a href="http://www.postfix.org/" target="_blank">Postfix</a> and <a href="http://www.courier-mta.org/imap/" target="_blank">Courier IMAP</a> and dependencies can all be installed via the package management system:</p>
<pre>$sudo apt-get install postfix fetchmail courier-imap sun-java6-jdk tomcat6 tomcat6-admin ant</pre>
<h3>Configure Certificates</h3>
<p>To be sure that we are actually connecting to Gmail and to encrypt e-mail to and from the service we need to set up a few certificates.</p>
<p>Create a local certificate store:</p>
<pre>$mkdir -p /etc/ssl/local/certs/</pre>
<p>Install the Thawte root CA certificate (required for Gmail SMTPS):</p>
<ul>
<li>Go to <a href="http://www.thawte.com/roots/" target="_blank">Thawte</a> and download their root CA certificates</li>
<li>Unzip the ZIP archive and locate the file: <em>Thawte Premium Server CA.cer</em></li>
<li>Convert the CA certificate to PEM format and install:</li>
</ul>
<pre>$sudo openssl x509 -inform der -in 'Thawte Premium Server CA.cer' -out /etc/ssl/local/certs/thawte.pem</pre>
<p>Install the Equifax root CA certificate (required for Gmail POP3S):</p>
<pre>$sudo wget -O /etc/ssl/local/certs/equifax.pem

https://www.geotrust.com/resources/root_certificates/certificates/

Equifax_Secure_Certificate_Authority.cer</pre>
<p>Install the Gmail POP3S certificate:</p>
<pre>$openssl s_client -connect pop.gmail.com:995 -showcerts</pre>
<p>From the output of the command select the pop.gmail.com certificate (the first block to appear between and including lines &#8220;&#8212;&#8211;BEGIN CERTIFICATE&#8212;&#8211;&#8221; and &#8220;&#8212;&#8211;END CERTIFICATE&#8212;&#8211;&#8221;) and copy and paste this into a new file:</p>
<pre>/etc/ssl/local/certs/googlepop.pem</pre>
<p>Hash the certificates:</p>
<pre>$sudo c_rehash /etc/ssl/local/certs</pre>
<a class="wazi-ad-link" href="http://www.openlogic.com/open-source-support.php "><img width="590" height="75" src="http://olex.openlogic.com/wazi/wp-content/uploads/2010/05/open-source-support-main.png" class="attachment-maincontent_ad" alt="Get open source software support" title="Get open source software support" /></a>
<h3>Build and Configure Davmail</h3>
<p>Grab the latest Davmail code from SVN. For checkout details see <a href="http://sourceforge.net/projects/davmail/develop" target="_blank">the Sourceforge page</a>. Then to build:</p>
<pre>$cd davmail/trunk
$ant</pre>
<p>If the build is successful proceed to configure the web application archive (WAR file) version of Davmail:</p>
<pre>$cd dist
$jar xvf davmail-N.N.N-NNN.war</pre>
<p>(replacing &#8216;N.N.N-NNN&#8217; with the version number)</p>
<p>Edit the file <em>WEB-INF/classes/davmail.properties</em> as appropriate, for example:</p>
<pre>davmail.url=https\://mail.acme.com/exchange/
davmail.popPort=1110
davmail.smtpPort=1025
davmail.ldapPort=1389
davmail.caldavPort=1080
davmail.keepDelay=60
davmail.sentKeepDelay=180
davmail.caldavPastDelay=60

davmail.enableProxy=false
davmail.proxyHost=
davmail.proxyPort=
davmail.proxyUser=
davmail.proxyPassword=

davmail.allowRemote=true
davmail.bindAddress=
davmail.server=true
davmail.disableUpdateCheck=false

log4j.logger.davmail=DEBUG
log4j.rootLogger=WARN
log4j.logger.httpclient.wire=WARN
log4j.logger.org.apache.commons.httpclient=WARN</pre>
<p>You should really only need to update <em>davmail.url</em> with the URL of your OWA service, but you may also choose to adjust the <em>davmail.*Delay</em> settings which control things such as for how many days messages that have been retrieved should be left on the Exchange server. However, note that the Postfix and Fetchmail configuration that follows assumes that you have set the POP3 and SMTP port numbers as detailed above.</p>
<p>Re-package the web application archive:</p>
<pre>$jar cvf davmail.war WEB-INF META-INF</pre>
<h3>Configure Tomcat and deploy Davmail</h3>
<p>Grant all Java security permissions to Davmail by editing the file <em>/etc/tomcat6/policy.d/50local.policy</em> and adding to the bottom:</p>
<pre>// Davmail
//grant codeBase "file:${catalina.base}/webapps/davmail/-" {
//        permission java.security.AllPermission;
//};</pre>
<p>Create a user for the Tomcat admin application by editing the file <em>/etc/tomcat6/tomcat-users.xml</em> and adding to the bottom:</p>
<pre>&lt;tomcat-users&gt;
&lt;role rolename="tomcat"/&gt;
&lt;role rolename="manager"/&gt;
&lt;user username="yourusername" password="yourpassword" roles="manager"/&gt;
&lt;/tomcat-users&gt;</pre>
<p>Substitute &#8220;yourusername&#8221; and &#8220;yourpassword&#8221; for the username and password you want to use for administering Tomcat.</p>
<p>Restart Tomcat:</p>
<pre>$sudo /etc/init.d/tomcat6 restart</pre>
<p>Deploy Davmail:</p>
<ul>
<li>Log in to the Tomcat admin application at http://yoursystem:8080/manager/html</li>
<li>From the <em>WAR file to deploy</em> section browse to the davmail.war archive we created earlier, and then select <em>Deploy</em>.</li>
<li>Davmail should now be listed in the <em>Applications</em> section. If Davmail is not showing as running select <em>Start</em> from the <em>Commands</em> column.</li>
</ul>
<h3>Configure Postfix</h3>
<p>For security reasons it makes sense to keep mail on-system whenever possible. Or to put it another way: if I send mail from my Acme Inc account to another Acme Inc user why route it via a 3rd party mail system? So, we&#8217;ll be explicit when it comes to mail routing.</p>
<p>Edit the file <em>/etc/postfix/main.cf</em> and set the following options:</p>
<pre>home_mailbox = Maildir/

smtp_tls_loglevel = 1
smtp_tls_per_site = hash:/etc/postfix/tls_per_site
smtp_tls_CAfile = /etc/ssl/local/certs/thawte.pem
smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache
smtp_use_tls = yes

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous

relayhost = [smtp.gmail.com]:587

disable_dns_lookups = yes

smtp_generic_maps = hash:/etc/postfix/generic

sender_dependent_relayhost_maps = hash:/etc/postfix/bysender</pre>
<p>Configure Postfix to route mail sent from the corporate account(s) to OWA via Davmail, by editing the file <em>/etc/postfix/bysender</em> and adding:</p>
<pre>@acme.com         [localhost]:1025</pre>
<p>Map any local users to routable mail addresses by editing the file <em>/etc/postfix/generic</em> and adding:</p>
<pre>ausername@yoursystem		someuser@acme.com</pre>
<p>Note: &#8216;yoursystem&#8217; is the system we are configuring, &#8216;ausername&#8217; is a Linux account on this system and the right hand address could be an Exchange or Google account. This configuration is optional and is only used where a MUA defaults to setting the originator address of a message to $LOGNAME@$HOSTNAME.</p>
<p>Store the authentication credentials for remote SMTP (and sending via OWA) by editing the file <em>/etc/postfix/sasl_passwd</em> and adding:</p>
<pre>[smtp.gmail.com]:587    auser@gmail.com:gmailpassword
[localhost]:1025        DOMAIN\USER:domainpassword</pre>
<p>Note: the 2nd line is specifying credentials that will be passed to OWA via Davmail, therefore &#8220;DOMAIN\USER&#8221; is the username half of Windows domain credentials. Ensure that this file is mode 640 and ownership root:postfix.</p>
<p>For security reasons force connections to Google&#8217;s SMTP service to use TLS by editing the file <em>/etc/postfix/tls_per_site</em> and adding:</p>
<pre>smtp.gmail.com         MUST</pre>
<p>Create the Postfix lookup tables:</p>
<pre>$cd /etc/postfix
$sudo postmap bysender
$sudo postmap generic
$sudo postmap sasl_passwd
$sudo postmap tls_per_site</pre>
<p>Restart Postfix:</p>
<pre>$sudo /etc/init.d/postfix restart</pre>
<p>Note: If you plan to use this configuration on a server you will likely want to configure Postfix to accept SMTP connections from remote MUAs over SSL. However, this is out of the scope of this tutorial.</p>
<h3>Configuring Courier IMAP</h3>
<p>Edit the file <em>/etc/courier/imapd</em> and ensure that the following variables are set (they should be found toward the bottom of the file):</p>
<pre>IMAPDSTART=YES

MAILDIRPATH=Maildir</pre>
<p>Edit the file <em>/etc/courier/authdaemonrc</em> and ensure that the following variable is set:</p>
<pre>authmodulelist="authpam"</pre>
<p>Note: If you plan to use this configuration on a server you will likely want to configure the Courier IMAP service to work over SSL. However, this is out of the scope of this tutorial.</p>
<h3>Configure the Local User Environment</h3>
<p>Create an initial maildir format mailbox:</p>
<pre>$maildirmake ~/Maildir</pre>
<p>Create a new file <em>~/.fetchmailrc</em> to hold the Fetchmail configuration:</p>
<pre>#
# ~/.fetchmailrc
#
# Check mail every 120 seconds
#
set daemon 120
set postmaster ausername
#
# Gmail
#
poll pop.gmail.com with proto POP3 and options no dns
        user 'auser@gmail.com' with pass "gmailpassword" is 'ausername'
        here options ssl sslcertck
sslcertpath '/etc/ssl/local/certs/'
        smtphost localhost
#
# ACME Inc
#
poll localhost with proto POP3 and options port 1110 no dns
        user "someuser@ACME" with pass "domainpassword" is 'ausername' here
        smtphost localhost
#</pre>
<p>Note: &#8220;ausername&#8221; is the local Linux account. SSL is not needed when retrieving mail from Exchange as the fetchmail -&gt; Davmail connection will be over localhost, and Davmail -&gt; OWA over https (unless your Exchange administrators have configured the OWA service to run over http).</p>
<p>Manually start Fetchmail in verbose mode and check for errors:</p>
<pre>$fetchmail -v</pre>
<p>Fetchmail can be configured to automatically start via a number of different mechanisms. For example, with Gnome desktop you could create a new &#8216;Startup Application&#8217; from System -&gt; Preferences, and have &#8216;/usr/bin/fetchmail&#8217; be executed on login. Or you could add fetchmail to your personal crontab, e.g.:</p>
<pre>*/2 * * * * /usr/bin/fetchmail -s</pre>
<p>When using cron you would remove the line starting <em>set daemon</em> from file <em>.fetchmailrc</em>.</p>
<h2>Finishing Up</h2>
<h3>Mail Client Settings</h3>
<p>If you are running a local MUA that supports the maildir mailbox format there should be nothing to configure other than the sending identities and application preferences. If you are using a local MUA that does not support maildir you should use IMAP and enter localhost for the server and use your Linux account credentials for authentication. If you are using this configuration on a server: for the MUA on the client you would use the server FQDN for the IMAP server and your Linux account credentials for authentication, and SMTP settings would depend on how you had configured SMTP authentication (incoming to the server).</p>
<p>Davmail also provides proxies for LDAP and <a href="http://en.wikipedia.org/wiki/CalDAV" target="_blank">CalDAV</a> to OWA:</p>
<ul>
<li>LDAP: server: <em>localhost:1389</em>; bind dn: <em>USER@DOMAIN</em>; password: <em>domainpassword</em>; search base: <em>ou=people</em>; search field: <em>sn </em></li>
<li><em>CalDAV: URL: <em>http://localhost:1080/users/someuser@acme.com/calendar/</em>; password: <em>domainpassword</em></em></li>
</ul>
<p><em>USER@DOMAIN and domainpassword are the credentials associated with your Windows domain account.</em></p>
<p><em>Note: Whenever your Windows domain password or Gmail password changes you will need to update this in <em>~/.fetchmailrc</em> and <em>/etc/postfix/sasl_passwd</em>, and execute <em>$sudo postmap /etc/postfix/sasl_passwd</em>.</em></p>
<h3><em>Conclusion</em></h3>
<p><em>The configuration detailed here is rather more complicated than ought to be and has wrinkles such as having to store user credentials in both Fetchmail and Postfix configuration. As such its appeal is likely limited to use with more complex mail requirements involving OWA and where there are few, if any, alternative options. Davmail could be used on its own for simple OWA access; however, the addition of Fetchmail and Postfix also means that e-mail is always stored in a standard format, maildir, and that where possible outbound e-mail is always kept on-system. The addition of Courier IMAP allows a greater number of local MUAs to be used (i.e. those that do not support maildir), and the configuration could be deployed to a server and the unified inbox synchronised across multiple desktops.</em></p>
<p><em>Finally, there is much room for improvement, and it would be great to see this configuration further developed such that user credentials were better handled and a practical, secure multi-user proxy server could be easily set up, thereby providing a shared service for Exchange OWA &lt;&#8212;&gt; standards-based (IMAP, SMTP, LDAP and CalDAV) MUA integration.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://olex.openlogic.com/wazi/2009/escaping-microsoft-exchange-via-davmail-fetchmail-postfix-courier-imap/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
