As root, install fetchmail
$ apt-get install fetchmail
Check if fetchmail has SSL support: if you see something like "libssl.so.0" then yours has it
$ ldd /usr/bin/fetchmail
Test Gmail SSL certificates
$ openssl s_client -connect pop.gmail.com:995
You should see something like "+OK Gpop ready for requests from ..."
$ wget -O ~/.fetchmailrc https://gist.github.com/cristianp6/c063e36826a6b1623f3d/raw/f429c4633992c9f8d95e2263c2876b7d38972912/fetchmailrc
$ chmod 0700 ~/.fetchmailrc
Edit the file with your settings
$ nano ~/.fetchmailrc
As 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/fetchmailhandler
Test fetchmail
$ fetchmail -d0 -vk -f .fetchmailrc
Kill eventual fetchmail daemon process with:
$ fetchmail -q
Find fetchmail path
$ whereis fetchmail
The path should be something like "fetchmail: /usr/bin/fetchmail ..."
$ crontab -e
# Fetch emails every 5 minutes max
*/5 * * * * /usr/bin/fetchmail > /dev/null 2>&1
Or start fetchmail daemon
$ fetchmail
Now 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
uidl
to thepoll ...
line in your.fetchmailrc
and 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
keep
to theuser
config line to be sure your client won't ask the server to purge the messages.