Python
  Home arrow Python arrow Page 2 - Python Email Libraries, part 1: POP3
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

Python Email Libraries, part 1: POP3
By: Michael Swanson
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 25
    2005-05-11


    Table of Contents:
  • Python Email Libraries, part 1: POP3
  • The POP Protocol
  • Getting Message Info
  • Getting Messages from the Server

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Python Email Libraries, part 1: POP3 - The POP Protocol
    ( Page 2 of 4 )

    Overall, POP is a relatively simple protocol; for instance, there is no definition for creating multiple message folders as there is in IMAP, as POP simply allows the client to connect and download from a list of messages available on the server. This means that the tasks available while connected to a POP server are relatively few. You can list the messages on the server, download either all or part of a message, and delete messages off of the server when they no longer need to stay there. 

    Originally, messages were not intended to remain on the server indefinitely, as many people are familiar with in most contemporary email systems. POP clients were designed to connect to the server, list the messages, download those the client wanted to read, and delete the downloaded messages. Nowadays, with most email accounts accessible over the Web as well as with a normal email client, this is not the preferred manner of use. Rather, most clients will download a message and generally leave the message on the server to allow access to the messages from more than a single PC. 

    Opening a POP Connection

    The first step necessary for downloading messages from the server is to open a connection to that server and authenticate the username and password against the server. The objects to connect with a POP server are contained within the poplib library that comes with the standard download of Python. This library contains the POP3 object which actually does the work of connecting to and communicating with the remote server. This task is really pretty simple:

     from poplib import *
     …
     server = POP3(“123.213.112.23”)
     print server.getwelcome()
     print server.user(“user”)
     print server.pass_(“password”)

    The first line in this block imports the necessary objects from the library. Next, the code creates a new POP3 object to connect with the server at 123.213.112.23. As you can tell from the later lines, all this does is open the basic network connection to the server; you must still log in with a username and password. 

    After creating the server object, we get the welcome string from the server. Some server administrators use this to disseminate information, so it can be a useful thing to know how to get. The last two lines of this code log in with a specific username and password. The second-to-last line sends the username and the last line sends the password.

    This example uses the older, relatively insecure POP authentication.  Python provides support for two additional authentication schemes. Both APOP and RPOP are implemented in standard Python. When to use each of these authentication schemes depends on the specific server implementation to which the client is connecting. 



     
     
    >>> More Python Articles          >>> More By Michael Swanson
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek