Retrieving Emails from POP3 Server

Post Office Protocol version 3 (POP3) is a standard mail protocol used to retrieve emails from a remote server to a local email client. As the oldest Internet message access protocol, it was designed to facilitate offline/local email processing. Emails are initially delivered to a mail server, and a remote email client periodically fetches the emails from the server to the user's computer. When checking emails using an email client, a connection is established with the mail server to download the emails onto the user's 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 utilize your Gmail account to receive emails from your domain email address by configuring your domain's email as a POP3 account within Gmail. The Python poplib module offers straightforward access to POP3 mail servers, enabling you to establish connections and efficiently retrieve messages using your Python scripts. This facilitates seamless integration and automation of email retrieval processes within your programming projects.

Gmail (POP) Server Settings

  1. Pop3Server : pop.gmail.com
  2. Requires SSL: Yes
  3. 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()

Conclusion

Retrieving emails from a POP3 server involves setting up your domain email as a POP3 account within Gmail and utilizing Python's poplib module to establish connections and retrieve messages. This process enables you to efficiently fetch and manage emails using your Python scripts.