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  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM developerWorks
 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? 
PYTHON

Python Email Libraries, part 1: POP3
By: Michael Swanson
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 22
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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


       · You should run your code before pasting it into your article. It's full of errors...
       · I'm Mike Swanson, the author of this article.I'm sorry my code isn't working for...
       · it was quite helpful. some small bugs are there but its ok.
       · Hi there, I found this very useful so thanks. However there are a few errors in this...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway