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:
  1. Port 110 - this is the default POP3 non-encrypted port

  2. Port 995 - this is the port you need to use if you want to connect using POP3 securely (SSL)
You can use your Gmail account to receive your domain email address by setting up your domains email address as a POP3 account at Gmail. The poplib module included with Python provides simple access to POP3 mail servers that allow you to connect and quickly retrieve messages using your Python scripts .

Gmail (POP) Server Settings

  1. Pop3Server :
  2. Requires SSL: Yes
  3. Port: 995
import poplib pop3server = '' username = '' 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()