I am sharing this script because it can help you learn how to retrieve new mails from an IMAP server and also send sms notifications.
The script is configured with webmail account of our institute and the sms is sent to my mobile. You can open the *.py file in any text editor and change the variable values to edit it according to your needs.
You can download the source code here.Just make the two scrips executable & send run webmail.py..
If you want to have an idea as to how I made the sms script, take a look at my previous post.
If you have any issues, leave comments..
Also, if the sms is not sent, checkout the method I wrote in this post..