As root, install fetchmail
$ apt-get install fetchmailCheck if fetchmail has SSL support: if you see something like "libssl.so.0" then yours has it
$ ldd /usr/bin/fetchmailTest Gmail SSL certificates
$ openssl s_client -connect pop.gmail.com:995You should see something like "+OK Gpop ready for requests from ..."
$ wget -O ~/.fetchmailrc https://gist.github.com/cristianp6/c063e36826a6b1623f3d/raw/f429c4633992c9f8d95e2263c2876b7d38972912/fetchmailrc
$ chmod 0700 ~/.fetchmailrcEdit the file with your settings
$ nano ~/.fetchmailrcAs root, create the "fetchmail handler"
$ wget -O /sbin/fetchmailhandler https://gist.githubusercontent.com/cristianp6/c063e36826a6b1623f3d/raw/06537116cfb81041932149257d68d2ffcc6f363a/fetchmailhandler
$ chmod +x /sbin/fetchmailhandler- Change the ownername as the username who have to read the file
- Change the filepath where you want to store the emails
$ nano /sbin/fetchmailhandlerTest fetchmail
$ fetchmail -d0 -vk -f .fetchmailrcKill eventual fetchmail daemon process with:
$ fetchmail -qFind fetchmail path
$ whereis fetchmailThe path should be something like "fetchmail: /usr/bin/fetchmail ..."
$ crontab -e
# Fetch emails every 5 minutes max
*/5 * * * * /usr/bin/fetchmail > /dev/null 2>&1Or start fetchmail daemon
$ fetchmailNow you can parse the file "/path/to/the/file/[unixtimeInMicroseconds].eml"
In case someone wanders here: because fetchmail with POP3 and the above configuration does not track what it has already fetched and what it hasn't.
You'd need to add
uidlto thepoll ...line in your.fetchmailrcand a location for the idfile (optional)fetchmail will track the message IDs it has already downloaded and won't fetch duplicates.
Also, with the above configuration a POP3 client would flag the messages for deletion on the server, which means that even without accounting for duplicates, you should not receive the same email twice, but this seems to be overrideable in Gmail in the "POP/IMAP" settings for the inbox and Gmail may keep the message anyway.
You may want to add
keepto theuserconfig line to be sure your client won't ask the server to purge the messages.