1. Home
  2. Computing & Technology
  3. Python

Retrieving POP3 Email with poplib

From , former About.com Guide

2 of 5

Getting the Server Information

We then should the same thing with the server, protocol, and port number. If you use this code for only one server, you can hardwire the values into the program, otherwise, you need to go back to the user:

server = raw_input('Server Address:')
type = raw_input('Encrypted with SSL (Y/N):')
port = raw_input('Port:')
We then need to follow this with an if loop to set the value for the mailbox object:
if type=="Y":
Mailbox = poplib.POP3_SSL(server, port)
else:
Mailbox = poplib.POP3(server, port)
This bit of code obviously expects the user to know the port number involved. With another if loop, however, one can allow for custom ports and defaults. POP3 defaults to port 110. POP3 over SSL (POP3_SSL) defaults to port 995.

Explore Python
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python
  4. Web Development
  5. Python Programming - Retrieving Email - Pop POP3 with poplib - Getting the Server Information

©2009 About.com, a part of The New York Times Company.

All rights reserved.