a starter - SMTP and POP3 Example : SMTP « Network « Python Tutorial -
Or from - Retrieving Email from a POP3 Server | Python Phrasebook: Implementing Internet Communication | InformIT -
import poplib
import getpass
mServer = poplib.POP3('mail.sfcn.org')
#Login to mail server
mServer.user(getpass.getuser())
mServer.pass_(getpass.getpass())
#Get the number of mail messages
numMessages = len(mServer.list()[1])
print "You have %d messages." % (numMessages)
print "Message List:"
#List the subject line of each message
for mList in range(numMessages) :
for msg in mServer.retr(mList+1)[1]:
if msg.startswith('Subject'):
print '\t' + msg
break
mServer.quit()
pop3_mail.py
password:
You have 10 messages.
Message List:
Subject: Static IP Info
Subject: IP Address Change
Subject: Verizon Wireless Online Statement
Subject: New Static IP Address
Subject: Your server account has been created
Subject: Looking For New Home Projects?
Subject: PDF Online - cl_scr_sheet.xls
Subject: Professional 11 Upgrade Offer
Subject: #1 Ball Played at the U.S. Open
Subject: Chapter 3 submission
Output from pop3_mail.py code