Wednesday, 1 October 2014

How to Read POP3 E-mail messages from accounts using python

Use below code for reading POP3 emails from any account.


import poplib
import getpass
serveur = poplib.POP3('mail.example.com')
#User Authentication
serveur.user(getpass.getuser())
serveur.pass_(getpass.getpass())
# Get message count
nbr_message = len(serveur.list()[1])
# print message subjects
for elem in range(nbr_message) :
    for msg in serveur.retr(elem+1)[1]:
        if msg.startswith('Subject'):
            print msg
            break
serveur.quit()

Thank you guys for your support.

No comments:

Post a Comment