Skip to Main Content
Python Programming On Win32
book

Python Programming On Win32

by Andy Robinson, Mark Hammond
January 2000
Intermediate to advanced content levelIntermediate to advanced
672 pages
21h 46m
English
O'Reilly Media, Inc.
Content preview from Python Programming On Win32

Receiving via POP3

POP3 downloads messages from a remote mailbox. As we discussed previously, SMTP is used typically to send Internet email messages, and POP3 receives them.

Like most Internet protocols, POP3 uses a line-based communications protocol, and also like most Internet protocols, you will find a Python module designed to ease working with that protocol; in this case the Python module is poplib .

Before delving into a discussion of POP3, it is worth noting that an improved protocol known as Internet Message Access Protocol (IMAP) has been designed. Although this fixes many of the shortcomings in the POP3 protocol, it’s not used as widely as POP3. Therefore, we will discuss using POP3 to ensure the code works on the widest possible range of mail servers. If you need to investigate using the IMAP protocol, you should view the module imaplib and its associated documentation.

There are three steps to establishing a connection to a POP3 mailbox:

  1. Connect to the server by creating a poplib.POP3() instance, specifying the hostname.

  2. Send the mailbox account name, using the user() method.

  3. Send the mailbox password using the pass_() method (pass is a reserved word in Python, hence the trailing underscore).

You now have a valid connection, and the mailbox is locked. While the mailbox is locked, no other connections are possible, so it’s important to unlock the mailbox when you’re done using the quit() method. If you don’t unlock the mailbox, other mail clients (such as your regular ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Programming - Second Edition

Advanced Python Programming - Second Edition

Quan Nguyen

Publisher Resources

ISBN: 1565926218Supplemental ContentErrata Page