Setup Mail

Setting up postfix for use on two networks

For each network, create a transport file, e.g. /etc/postfix/transport.sun:

localhost                 :
localhost.localdomain     :
*                     smtp:[]

In /etc/postfix/, have

myhostname = localhost
myorigin = $myhostname
mydestination = localhost, localhost.localdomain

transport_maps = hash:/etc/postfix/transport

Now, when switching over to a specific network,

ln -sf /etc/postfix/transport.sun /etc/postfix/transport
postmap hash:/etc/postfix/transport
/etc/init.d/postfix reload

reconfigures postfix to use the appropriate transport.

Here is a script which does the switching:



if [ -z $TRANSPORT ]; then
    echo "Usage: mail-switch provider"
    echo "Provider can be one of:"
    ls $BASE/transport.* | grep -v "~" | grep -v '.db' | python -c \
"import os, sys;
for f in sys.stdin: print os.path.basename(f).replace('transport.',''),"
    exit 0


if [ ! -f $FN ]; then
    echo "Transport file does not exist. Aborting."
    exit 0

echo "Switching postfix configuration to [$TRANSPORT]..."
cd $BASE
rm transport
ln -s $FN transport
postmap transport
/etc/init.d/postfix reload

Furthermore, we need to configure postfix to rewrite the "From:" header for all remotely delivered e-mails. We do this by setting up an SMTP map in /etc/postfix/

smtp_generic_maps = hash:/etc/postfix/generic

with /etc/postfix/generic containing:


Remember to rehash the file by doing

$ sudo postmap hash:/etc/postfix/generic


Example ~/.fetchmailrc:

set postmaster "stefan"
poll protocol imap username stefan password xxx ssl

To add this to your crontab, do

$ crontab -u stefan -e

and add the line

*/5 * * * * /usr/bin/fetchmail -a > /dev/null 2>&1

to check for mail every 5 minutes.

(Btw, the crontabs are located in /var/spool/cron/crontabs, but you shouldn't need to access those files directly.)

Setting up mutt

Setup personal preferences in ~/.muttrc:

# -*- muttrc -*-

source ~/.mutt-common

# Personal
set from="Stefan van der Walt <>"
set editor="emacs -q %s -f auto-fill-mode -fn Monospace-10"
set use_from=yes

# Boxes
set mbox="=archive/read-2007-3"
set record="=archive/sent-2007-3"

mailboxes \
/var/spool/mail \
=inbox \
`echo ~/Mail/lists/*` \
`echo ~/Mail/todo/*`

and place the common configuration in ~/.mutt-common:

# Key bindings
macro index <f1> "<limit>.*<enter><show-limit>" "Clear current limit"
macro index <f2> "<limit>~O | ~N<enter><show-limit>" "Show all unread messages"
macro index <f3> "<limit>~C scipy.* | ~C numeric | ~C numpy<enter><show-limit>" "Show the SciPy mailing lists"
macro index <f4> "<limit>~C | ~C<enter><show-limit>" "Show the iPython mailing lists"
macro index <f5> "<limit>~C muse<enter><show-limit>" "Show the muse mailing list"
macro pager Z "<pipe-message>~/bin/<enter>" "Unzip and display MIME attachments"

# Boxes
open-hook \\.gz$ "gzip -cd %f > %t"
close-hook \\.gz$ "gzip -c %t > %f"
append-hook \\.gz$ "gzip -c %t >> %f"
set move=ask-yes
set mark_old=yes
set sort=threads

# Adresses
macro pager A |'abook --add-email'\n
source =aliases
set alias_file="=aliases"
set query_command="lbdbq %s"

# Aliases
source =aliases
set alias_file="=aliases"

# Spelling
set ispell="/usr/bin/aspell -e -c"

# HTML and other annoying attachments
#auto_view text/*
#unauto_view text/plain
auto_view text/html

# Lists
subscribe .*
subscribe .*
subscribe .*
subscribe .*
subscribe .*
subscribe .*

# Interface
set quit=ask-yes
set xterm_set_titles=yes
set index_format="%4C %Z %{%b %d} %-15.15F (%?l?%4l&%4c?) %s"
set pager_stop
set print_command="muttprint"
set charset=utf-8
set mime_forward=ask-yes
set pager_index_lines=5
set simple_search="~f %s | ~C %s | ~s %s"
set nomarkers
unset mark_old

# Headers
ignore *
unignore From:
unignore To:
unignore Reply-To:
unignore Mail-Followup-To:
unignore Subject:
unignore Date:
unignore Organization:
unignore Newsgroups:
unignore CC:
unignore BCC:
unignore Message-ID:
unignore X-Mailer:
unignore User-Agent:
unignore X-Junked-Because:
unignore X-SpamProbe:
unignore X-Virus-hagbard:
hdr_order From: To: Subject: CC: BCC: Reply-To: Mail-Followup-To: Date: Organization: User-Agent: X-Mailer:
color header brightcyan black From
color header brightcyan black Subject

Setting up procmail

These days, no .forward file is necessary. Just edit the ~/.procmailrc:


* ^List-Id:.*ipython.*

* ^List-Id:.*

* ^From:.*

* ^List-Id:.*

* ^List-Id:.*

* ^List-Id:.*

sub-sahara africa
sahara trip IanKnot rainbow