For each network, create a transport file, e.g. /etc/postfix/transport.sun:
localhost : localhost.localdomain : * smtp:[mail1.sun.ac.za]
In /etc/postfix/main.cf, 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:
#!/bin/bash BASE=/etc/postfix TRANSPORT=$1 if [ -z $TRANSPORT ]; then echo "Usage: mail-switch provider" echo 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 fi FN=$BASE/transport.$TRANSPORT if [ ! -f $FN ]; then echo "Transport file does not exist. Aborting." exit 0 fi 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/main.cf:
smtp_generic_maps = hash:/etc/postfix/generic
with /etc/postfix/generic containing:
stefan@localhost stefan@sun.ac.za
Remember to rehash the file by doing
$ sudo postmap hash:/etc/postfix/generic
Example ~/.fetchmailrc:
set postmaster "stefan" poll zaphod.lagged.za.net 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.)
Setup personal preferences in ~/.muttrc:
# -*- muttrc -*- source ~/.mutt-common # Personal set from="Stefan van der Walt <stefan@sun.ac.za>" 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.*@scipy.net | ~C numeric | ~C numpy<enter><show-limit>" "Show the SciPy mailing lists" macro index <f4> "<limit>~C ipython-dev@scipy.net | ~C ipython-user@scipy.net<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/zipfilter.py<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 .*@octave.org subscribe .*@sulug.sun.ac.za subscribe .*@scipy.net subscribe .*@scipy.org subscribe .*@lists.sourceforge.net subscribe .*@gna.org # 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
These days, no .forward file is necessary. Just edit the ~/.procmailrc:
SHELL=/bin/bash LOGFILE=$HOME/procmail.log MAILDIR=$HOME/Mail :0: * ^List-Id:.*ipython.*.scipy.org lists/ipython :0: * ^List-Id:.*.scipy.org lists/scipy :0: * ^From:.*tickets@scipy.net lists/scipy :0: * ^List-Id:.*matplotlib-devel.lists.sourceforge.net lists/matplotlib :0: * ^List-Id:.*enthought-dev.mail.enthought.com lists/enthought :0: * ^List-Id:.*muse-el-discuss.gna.org lists/muse