Retrieving Emails from POP3 Server
Post Office Protocol version 3 (POP3) is a standard mail protocol used to receive emails from a remote server to a local email client. It is the oldest Internet message access protocol and it was designed to support offline/local email processing. Email is delivered to a mail server and a remote email client periodically downloads the email from the server to the user's computer. When you check your email using an email client, it makes a connection to your mailserver and downloads your emails on to your computer. By default, the POP3 protocol works on two ports:- Port 110 - this is the default POP3 non-encrypted port
- Port 995 - this is the port you need to use if you want to connect using POP3 securely (SSL)
Gmail (POP) Server Settings
- Pop3Server : pop.gmail.com
- Requires SSL: Yes
- Port: 995
import poplib
pop3server = 'pop.gmail.com'
username = 'username@gmail.com'
password = 'your_password'
pop3server = poplib.POP3_SSL(pop3server) # open connection
print (pop3server.getwelcome()) #show welcome message
pop3server.user(username)
pop3server.pass_(password)
pop3info = pop3server.stat() #access mailbox status
mailcount = pop3info[0] #toral email
print("Total no. of Email : " , mailcount)
print ("\n\nStart Reading Messages\n\n")
for i in range(mailcount):
for message in pop3server.retr(i+1)[1]:
print (message)
pop3server.quit()
Related Topics
- How to find hostname of a computer - Python
- How To Find IP Address In Python
- Send mail from Gmail account using Python
- Retrieving Web Pages with HTTP using Python
- How to open a web browser using Python
- Creating an FTP client in Python
- Socket Programming in Python
- Multi threaded socket programming in Python