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"
Thank you - all up after adding the ; on line 7