Taylorbyte.com

Documentation Wiki

.fetchmailrc

How to setup .fetchmailrc for multiple virtual users running fetchmail in daemon mode and keeping idle IMAP connections to download accounts to local vmail users

Directory structure

In this wiki vmail is a linux user and contains 1 domain and 1 example user called vuser1

vmail
  domain
    vuser1

Each virtual user keeps their settings in their own virtual user folder.

Create a .fetchmail folder in the vitual user folder. For each external email this virtual user want's to download, create a folder inside of .fetchmail

mkdir /home/vmail/domain/vuser1/.fetchmail
mkdir /home/vmail/domain/vuser1/.fetchmail/smith@yahoo.com.au
mkdir /home/vmail/domain/vuser1/.fetchmail/smith@gmail.com
mkdir /home/vmail/domain/vuser1/.fetchmail/smith@hotmail.com

Inside each folder under .fetchmail create separate .fetchmailrc files

create .fetchmailrc file

cat > /home/vmail/domain/vuser1/.fetchmail/smith@yahoo.com.au/.fetchmailrc << EOF
set daemon 300
set no softbounce

poll imap.mail.yahoo.com
 protocol IMAP
 user "smith"
 pass ""
 is "vuser1@yourserver.com"
 fetchall
 idle
 ssl
EOF

chmod 700 -R .fetchmail

.fetchmailrc examples

Yahoo POP3 (plus.pop.mail.yahoo.com)

set daemon 300
set no softbounce

poll plus.pop.mail.yahoo.com
 protocol POP3
 user "smith"
 pass ""
 is "vuser1@yourserver.com"
 fetchall

Hotmail POP3 (pop3.live.com)

set daemon 300
set no softbounce

poll pop3.live.com
 protocol POP3
 service 995
 user "smith@hotmail.com"
 pass ""
 is "vuser1@yourserver.com"
 fetchall
 ssl

Gmail POP3 (pop.gmail.com)

set daemon 300
set no softbounce

poll pop.gmail.com
 protocol POP3
 service 995
 user "smith"
 pass ""
 is "vuser1@yourserver.com"
 fetchall
 ssl

Yahoo IMAP (imap.mail.yahoo.com)

set daemon 300
set no softbounce

poll imap.mail.yahoo.com
 protocol IMAP
 service 993
 user "smith"
 pass ""
 is "vuser1@yourserver.com"
 fetchall
 idle
 ssl

Gmail IMAP (imap.gmail.com)

set daemon 300
set no softbounce

poll imap.gmail.com
 protocol IMAP
 service 995
 user "smith"
 pass ""
 is "vuser1@yourserver.com"
 fetchall
 idle
 ssl

Other options

ssl sslcertpath /etc/ssl/certs/

fetchscript

Run this script with this command on boot sudo -u vmail ./fetchscript and every external email address will have its own daemon.

#!/bin/sh
cd ~/domain
for user in *; do
  if [ -e $user/.fetchmail ]; then
    cd $user/.fetchmail
    if [ -n "find | grep .fetchmailrc" ]; then
      for i in `find | grep .fetchmailrc`; do
        export FETCHMAILHOME=`echo $i | sed 's/\/.fetchmailrc//g'`
        fetchmail -f $i > /dev/null 2>/dev/null
        export FETCHMAILHOME=""
      done
    fi
    cd ../..
  fi
done
Creative Commons License

This guide is licensed under a Creative Commons Attribution-NoDerivs 3.0 Australia License.

Last edited by Brenton Taylor on Wednesday, November 9th, 2011 (r2085).