All Courses

Python - POP3

Neha Kumawat

a year ago

Python - POP3 | insideAIML
Table of Contents
  • Introduction
  • POP Commands

Introduction

          The pop3 protocol is an email protocol to download messages from the email-server. These messages can be stored in the local machine.
Key Points
  • POP is an application layer internet standard protocol.
POP is an application layer internet standard protocol.
  • Since POP supports offline access to the messages, thus requires less internet usage time.
Since POP supports offline access to the messages, thus requires less internet usage time.
  • POP does not allow search facility.
POP does not allow search facility.
  • In order to access the messaged, it is necessary to download them.
In order to access the messaged, it is necessary to download them.
  • It allows only one mailbox to be created on server.
It allows only one mailbox to be created on server.
  • It is not suitable for accessing non mail data.
It is not suitable for accessing non mail data.
  • POP commands are generally abbreviated into codes of three or four letters. Eg. STAT.
POP commands are generally abbreviated into codes of three or four letters. Eg. STAT.

POP Commands

         The following table describes some of the POP commands:
Pyhton’s poplib module provides classes named pop() and pop3_SSL() which are used to achieve this requirement. We supply the hostname and port number as argument. In the below example we connect to a gmail server and retrieve the messages after supplying the login credentials.

import  poplib

user = 'username' 
# Connect to the mail box 
Mailbox = poplib.POP3_SSL('pop.googlemail.com', '995') 
Mailbox.user(user) 
Mailbox.pass_('password') 
NumofMessages = len(Mailbox.list()[1])
for i in range(NumofMessages):
    for msg in Mailbox.retr(i+1)[1]:
        print msg
Mailbox.quit()
The messages are retrieved when the above program is run.
   
Liked what you read? Then don’t break the spree. Visit our insideAIML blog page to read more awesome articles. 
Or if you are into videos, then we have an amazing Youtube channel as well. Visit our InsideAIML Youtube Page to learn all about Artificial Intelligence, Deep Learning, Data Science and Machine Learning. 
Keep Learning. Keep Growing. 

Submit Review