Support #475
Updated by Daniel Curtis over 9 years ago
{{>toc}} Getmail is a useful tool for fetching mail from a remote mail server and delivering them to local mail account. This is useful for keeping emails concurrent between different mail servers if used as a cron job. h2. Install Getmail * Update ports tree: <pre> portsnap fetch extract </pre> * Install Getmail: <pre> cd /usr/ports/mail/getmail make install clean </pre> * Prepare getmail environment: <pre> cd mkdir .getmail cp /usr/local/share/examples/getmail/getmailrc-examples .getmail/getmailrc </pre> * Edit the .getmail/getmailrc file to suit your remote servers information. h3. Retrieving Emails * Create a separate getmail rc file for each account, and run getmail with multiple --rcfile options. <pre> cd ~/.getmail mkdir getmail.d </pre> * Create first user and deliver using dovecot <pre> vi ~/.getmail/getmail.d/john.getmailrc </pre> #* And and the following: <pre> ## john@example.com [options] verbose = 0 read_all = false delete = false [retriever] type = SimplePOP3Retriever server = mail.example.com username = john@example.com password = Password [destination] type = MDA_external path = /usr/local/libexec/dovecot/deliver arguments = ("-e", "-f", "%(sender)", "-d", "john@altservice.com") </pre> * Create next user and deliver to the users Maildir <pre> vi ~/.getmail/getmail.d/bob.getmailrc </pre> #* And add the following: <pre> ## bob@example.com [options] verbose = 0 read_all = false delete = false [retriever] type = SimplePOP3Retriever server = mail.example.com username = bob@example.com password = Password [destination] type = Maildir path = /var/vmail/vmail1/example.com/b/o/b/bob-2014.03.29.11.08.32/Maildir </pre> h3. Automate Getmail * Of course, it's really easy to script this for a large number of rc-* files. Create a script: <pre> vi /usr/local/bin/run-getmail.sh </pre> #* And add the following containing: followingcontaining: <pre> #!/bin/sh set -e cd /var/vmail rcfiles="" for file in `ls /var/vmail/.getmail/*.getmailrc` ; do rcfiles="$rcfiles --rcfile $file" done exec /usr/local/bin/getmail $rcfiles $@ </pre> * Make the script executable: <pre> chmod +x /usr/local/bin/run-getmail.sh </pre> * Edit the vmail crontab: <pre> su - vmail crontab -e </pre> #* And add the following to run the run-getmail.sh script every 2 minutes. <pre> */2 * * * * /usr/local/bin/run-getmail </pre>