After some fiddling around with fetchmail, the following is meant as note to self and for those who may find it useful...
Fetchmail is a small but powerful tool that can be used (in many ways) to retrieve email from a remote server using pop3, IMAP, and other popular protocols. It can reroute the fetched mail to a local account, system or simply pass it through to another SMTP service.
In my situation I was looking to add a couple of remote pop mail accounts to our Groupwise system (delivering different pop mail to specific mailboxes) without having to setup a client pop account (letting our Groupwise GWIA server handle this).
My setup in a nutshell:
Fetchmail runs on Linux. Our GWIA is running on a SLES 10 server and after installing the fetchmail package using YaST, I've let it run using cron on a normal user account.
What I did to get things running
When running fetchmail without parameters, the progam will look for the file .fetchmailrc in the current users homedir root.
Use or create a user account of choice and;
create a file .fetchmailrc
touch .fectchmailrc
change user rights .fetchmailrc (or fetchmail won't run)
chmod 600 .fetchmailr
Now edit .fetchmailrc to reflect all accounts and options you need
Example of .fetchmailrc (note: the file is configured specifically for my neeeds. Do have a good look at the man pages on options you need).
Essentially the configuration pulls mail from mail.sample.nl (from the account dude1 and dude2) and offers them to the gwia found at internalserver.nl with the rcpt set to mailboxes dude1-delivery-address@internaldomain.nl & dude2-delivery-address@internaldomain.nl
--beginning of file
#Note: running a system-wide fetchmail daemon doesn' use users' .fetchmailrc but only reads /etc/fetchmailrc. Therefor run as a user
#check mail on mail.sample.nl for accounts;
poll mail.sample.nl with proto POP3
#dude1@sample.nl
user 'dude1@sample.nl' password '' smtpname dude1-delivery-address@internaldomain.nl smtphost internalserver.nl no rewrite keep
#dude2@sample.nl
user 'dude2@sample.nl' password '' smtpname dude2-delivery-address@internaldomain.nl smtphost internalserver.nl no rewrite keep
#check mail on mail.otherserver.nl for accounts;
poll mail.otherserver.nl proto POP3
#otheraccount1@otherserver.nl
user 'otheraccount1' password 'otherpassword' smtpname otheraccountm-delevery-adderss@internaldomain.nl smtphost internalserver.nl no rewrite keep
--end of file
You can now simply run 'fetchmail -v' to see if your configuration is working as planned...
Add fetchmail to the users crontab
crontab -e #to edit the current users cron schedules
*/3 * * * * fetchmail -Ev > fetchmail.log
fetchmail now gets run every 3 minutes.
Note: The E uses the envolope mode, keeping as much of the recipient headers in tackt - for out setup this works perfectly.
The v is for verbose output that will be piped to the log file indicated. This log is meant for simple troubleshooting.
crontab -l # list current crontab entries
check if the command is listed
Things to think about:
- flushing mail on the remote server (option keep keeps the mail on the remote server - I've scheduled a monthly flush)
- read through the man pages (man fetchmail) to get a good 'feel' of the options and what they do
You can also test fetchmail functionality using the command line, as example:
fetchmail -S [SMTP server to forward to] -p pop3 -k -u [remote user] -v -U [remote mail server]
You should be prompted for the user password after entering the above command.
Hope you find these notes useful ;)
