Support #475
Using Getmail on FreeBSD
Status:
Closed
Priority:
Normal
Assignee:
Category:
Command-Line Help
Target version:
Description
- Table of contents
- Install Getmail
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.
Install Getmail¶
- Update ports tree:
portsnap fetch extract
- Install Getmail:
cd /usr/ports/mail/getmail make install clean
- Prepare getmail environment:
cd mkdir .getmail cp /usr/local/share/examples/getmail/getmailrc-examples .getmail/getmailrc
- Edit the .getmail/getmailrc file to suit your remote servers information.
Retrieving Emails¶
- Create a separate getmail rc file for each account, and run getmail with multiple --rcfile options.
cd ~/.getmail mkdir getmail.d
- Create first user and deliver using dovecot
vi ~/.getmail/getmail.d/john.getmailrc
- And and the following:
## 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")
- And and the following:
- Create next user and deliver to the users Maildir
vi ~/.getmail/getmail.d/bob.getmailrc
- And add the following:
## 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
- And add the following:
Automate Getmail¶
- Of course, it's really easy to script this for a large number of rc-* files. Create a script:
vi /usr/local/bin/run-getmail.sh
- And add the following containing:
#!/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 $@
- And add the following containing:
- Make the script executable:
chmod +x /usr/local/bin/run-getmail.sh
- Edit the vmail crontab:
su - vmail crontab -e
- And add the following to run the run-getmail.sh script every 2 minutes.
*/2 * * * * /usr/local/bin/run-getmail.sh
- And add the following to run the run-getmail.sh script every 2 minutes.