First you will need to install fecthmail.
You need to create one hidden file with email user’s details with “.fetchmailrc” name.
poll YOUR_MAIL_SERVER_HERE.com protocol IMAP:
user YOUR_USER_ID_HERE with password YOUR_PASSWORD_HERE some text
Then to fetch the mail you will have to fire this in order to flush the mail from your exchange server.
#/usr/local/bin/fetchmail -a -K -v -F –limitflush –limit 5