Scott Hurring » HOWTO » Debian: Setting up a mail server

HOWTO
info
Updated: Nov 06, 2005

Problem

I wanted to setup my local debian server to download each of my different email addresses and store it locally so that i could access it from each of my different home machines.

I setup fetchmail to grab the email from all my different POP3 email accounts, run it through procmail/spamassassin locally to filter out evil spam and then deliver it to $HOME/Maildir. Courier is then used to serve up the Maildir via IMAP to the machines on my local home network.

This way, i can connect to the local IMAP server from any of the machines on my local network and see the same exact view of my email.

Solution

1. Install Courier-IMAP

Install Courier-IMAP: apt-get install courier-imap courier-imap-ssl
Courier was pretty easy to get running, there was little or no configuration to be done.

2. Install + Configure Exim

Install exim: apt-get install exim
I selected "(1) Chose this if none of the other options exactly fit your needs" from the config menu and configured exim.conf by hand (see below).

3. Modify exim.conf

Choose one of the following ways to handle mail delivery. (I ripped most of this section from the very excellent page: Configuring Exim and Courier-IMAP, many thanks Jason).

Option 1: Sitewide Maildir support

local_delivery:
  driver = appendfile
  group = mail
  mode = 0660
  mode_fail_narrower = false
  envelope_to_add = true
  return_path_add = true

  directory=${home}/Maildir
  maildir_format = true
  prefix = ""

Option 2: Per-user Maildir support using a .forward file

address_directory:
  driver = appendfile
  no_from_hack
  prefix = ""
  suffix = ""
  maildir_format
  
[...]
 
userforward:
  driver = forwardfile
  file_transport = address_file
  pipe_transport = address_pipe
  reply_transport = address_reply
  
  directory_transport = address_directory
  
  no_verify
  check_ancestor
  check_local_user
  file = .forward
  modemask = 002
  filter

If you choose Option 2, your ~/.forward file should contain just a path to your maildir (i.e. /home/username/Maildir/)

Checkpoint 1: Test Courier + Exim

As Jason describes in: Configuring Exim and Courier IMAP, a good way to test is to attempt to send an email to yourself via exim:

# mail -s "test message" username[ENTER]
test[ENTER]
^D
Cc:[ENTER]
^D is Control-D, not the individual "^" and "D" characters

Configuring /etc/login.defs - for console applications

QMAIL_DIR    Maildir/
#MAIL_DIR              (comment this out)
MAIL_FILE    Maildir/
Log into IMAP - If everything is configured, you should see something like this

scott@tomb [~]$ telnet snark imap2
Connected to snark.
Escape character is '^]'.
* OK Courier-IMAP ready. Copyright 1998-2002 Double Precision, Inc. 
ab login "username" "password"
ab OK LOGIN Ok.
bc select "Inbox"
* FLAGS (\Draft \Answered \Flagged \Deleted \Seen \Recent)
* OK [PERMANENTFLAGS (\Draft \Answered \Flagged \Deleted \Seen)] Limited
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1056081360] Ok
bc OK [READ-WRITE] Ok
zzzz logout
* BYE Courier-IMAP server shutting down
zzzz OK LOGOUT completed
Connection closed by foreign host.
scott@tomb [~]$ 

4. Install + Confige fetchmail

Configuring fetchmail was pretty quick. After scouring google for a couple minutes to find a good example of fetchmail syntax, i made my own "poll" lines. Here's an example line from my .fetchmailrc. Procmail is used to filter email through spamassassin and sort it into folders.
poll hurring.com proto pop3 user
        "user@hurring.com" password "password",
        is "scott" here
        mda "/usr/bin/procmail";
This stanza tells fetchmail to go and get my emails from hurring.com and then pass them along to procmail as local user "scott" which means it will read /home/scott/.procmailrc and deliver the mail into /home/scott/Maildir.

To test, run: fetchmail -kv The -k option tells fetchmail to not delete any email from your POP3 mailbox, and the -v option gives verbosity.

5. Configuring procmail

This step would've been much harder if not for the great config example on Spamassassin's website: procmailrc.example

I took the example .procmailrc from the spamassassin website and added some additional rules to filter my mail into different folders depending on some simple rules.

This is my .procmailrc


Notes

References

Software referenced