Book Image

Learning Python Network Programming

By : Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington
Book Image

Learning Python Network Programming

By: Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington

Overview of this book

Table of Contents (17 chapters)
Learning Python Network Programming
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Retrieving e-mails by using POP3 with poplib


The stored e-mail messages can be downloaded and read by the local computer. The POP3 protocol can be used to download the messages from the e-mail server. Python has a module called poplib, and it can be used for this purpose. This module provides two high-level classes, POP() and POP3_SSL(),which implement the POP3 and POP3S protocols respectively for communicating with a POP3/POP3S server. It accepts three arguments, host, port, and timeout. If port is omitted, then the default port (110) can be used. The optional timeout parameter determines the length (in seconds) of the connection timeout at the server.

The secure version of POP3() is its subclass POP3_SSL(). It takes additional parameters, such as keyfile and certfile, which are used for supplying the SSL certificate files, namely the private key and certificate chain file.

Writing for a POP3 client is also very straightforward. To do this, instantiate a mailbox object by initializing the...