Apache James fetchmail configuration

The purposes of this tutorial, is getting James set-up to mirror a remote IMAP account locally. Specifically this will be a Gmail account. For the purposes of composing this tutorial, I have used and Ubuntu Intrepid server installation with the sun-java6-jre and ca-certificates-java packages installed.

The first problem I had with Apache James was finding where the configuration files live. So for our purposes, the two we are interested in are -:

james-2.3.1/apps/james/SAR-INF/config.xml
james-2.3.1/apps/james/conf/james-fetchmail.xml

Adding Users

Firstly you will need to start the Apache James services -:

/path/to/james/bin/run.sh

Now to add a new user to James, telnet to the management port on the James server, this is port 4555 by default, login with the root user and have a look at the following output to see how easy it is to add a new user.

JAMES Remote Administration Tool 2.1.2
Please enter your login and password
Login id:
root
Password:
root
Welcome root. HELP for a list of commands
adduser red red
User red added
listusers
Existing accounts 1
user: blue
quit
Bye

You now have a user called ‘red’ in your Apache James system, and mail destined to red@localhost will get delievered to this account.

mySQL Database Backend

For this project I was instructed that all mails should be stored in a MySQL database. Fortunately, Apache James makes this rather easy to achieve. The first thing to do is to create the database within MySQL and grant a user full rights on it -:

mysql> create database mail;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on mail.* to user@localhost identified by 'password';
Query OK, 0 rows affected (0.02 sec)

You will need to install the Java MySQL driver within James, firstly download the Java MySQL connector from here, then extract and copy the jar file over to your James installation -:

tar -xvzf mysql-connector-java-3.1.14.tar.gz
cp mysql-connector-java-3.1.14/*.jar /path/to/james/lib/

Now you need to edit you config.xml file, and add the following to enable MySQL within James.

 <data-source name="maildb">
 <driver>com.mysql.jdbc.Driver</driver>
 <dburl>jdbc:mysql://127.0.0.1/mail?autoReconnect=true</dburl>
 <user>user</user>
 <password>password</password>
 <max>20</max>
 </data-source>

Now set the delivery location of the mailboxes to be the database -:

<inboxRepository>
   <repository destinationURL="db://maildb/inbox/" type="MAIL"/>
</inboxRepository>

And that’s all there is to it, after restarting James, all email accounts will be stored in MySQL.

DNS Settings

Now I did find I needed to tweak some DNS settings before mail was delivered reliably, so in config.xml set autodiscovery to off and add a valid DNS server -:

<dnsserver>
<servers>
<server>192.168.255.1</server>
</servers>
<autodiscover>false</autodiscover>
<authoritative>false</authoritative>
<maxcachesize>50000</maxcachesize>
</dnsserver>

Fetchmail

Add to james-fetchmail.xml for Imap retrieval and placing in local users mailbox -:

 <fetchmail enabled="true">
 <fetch name="domain.com">
 <accounts>
 <account user="user" password="password" recipient="red@localhost" ignorercpt-header="true"/>
 </accounts>
 <host>mail.domain.com</host>
 <interval>600000</interval>
 <javaMailProviderName>imaps</javaMailProviderName>
 <javaMailFolderName>INBOX</javaMailFolderName>
 <javaMailProperties>
 <property name="mail.imaps.connectiontimeout" value="180000"/>
 <property name="mail.imaps.timeout" value="180000"/>
 </javaMailProperties>
 <fetchall>true</fetchall>
 <recursesubfolders>false</recursesubfolders>
 <fetched leaveonserver="true" markseen="true"/>
 <remotereceivedheader index="1" reject="false" leaveonserver="true" markseen="false"/>
 <maxmessagesize limit="0" reject="false" leaveonserver="true" markseen="false"/>
 <undeliverable leaveonserver="true" markseen="false"/>
 <recipientnotfound defer="true" reject="false" leaveonserver="true" markseen="false"/>
 <blacklist reject="true" leaveonserver="true" markseen="false"> dodgy@localhost </blacklist>
 <userundefined reject="false" leaveonserver="true" markseen="false" />
 <remoterecipient reject="false" leaveonserver="true" markseen="false" />
 </fetch>
 </fetchmail> 

For IMAP over SSL to work, I had to copy sunjce_provider.jar from jre6path/lib/ext to jamespath/lib

Incoming search terms:

  • fetchmail settings mysql
  • mod_security tutorial
Tagged with: , , , ,
Posted in Linux

Leave a Reply

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

*

* Copy this password:

* Type or paste password here:

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>