Home arrow Python arrow Page 2 - A PyMailGUI Demo

Loading Mail - Python

In last week's article, we introduced the PyMailGUI client, part of a Python program that sends, receives, composes, and parses Internet email messages. This week, we'll begin walking you through a PyMailGUI demo. This article, the second of six parts, is excerpted from chapter 15 of the book Programming Python, Third Edition, written by Mark Lutz (O'Reilly, 2006; ISBN: 0596009259). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

  1. A PyMailGUI Demo
  2. Loading Mail
  3. Threading Model
  4. Load Server Interface
By: O'Reilly Media
Rating: starstarstarstarstar / 1
July 19, 2007

print this article



Now, let’s go back to the PyMailGUI main server list window, and click the Load button to retrieve incoming email over the POP protocol. PyMailGUI’s load function gets account parameters from the mailconfig module listed later in this chapter,

Figure 15-5.  PyMailGUI attached PyEdit info box

so be sure to change this file to reflect your email account parameters (i.e., server names and usernames) if you wish to use PyMailGUI to read your own email.

The account password parameter merits a few extra words. In PyMailGUI, it may come from one of two places:

Local file
If you put the name of a local file containing the 
   password in themailconfigmodule, PyMailGUI 
   loads the password from that file as needed.

Popup dialog
If you don’t put a password filename inmailconfig 
   (or if PyMailGUI can’t load it from the file for whatever
   reason), PyMailGUI will instead ask you for your 
   password anytime it is needed.

Figure 15-6 shows the password input prompt you get if you haven’t stored your password in a local file. Note that the password you type is not shown—ashow='*'option for theEntryfield used in this popup tells Tkinter to echo typed characters as stars (this option is similar in spirit to both thegetpassconsole input module we met earlier in the prior chapter, and an HTMLtype=passwordoption we’ll meet in a later chapter). Once entered, the password lives only in memory on your machine; PyMailGUI itself doesn’t store it anywhere in a permanent way.

Also notice that the local file password option requires you to store your password unencrypted in a file on the local client computer. This is convenient (you don’t need to retype a password every time you check email), but it is not generally a good idea on a machine you share with others; leave this setting blank inmailconfigif you prefer to always enter your password in a popup.

Once PyMailGUI fetches your mail parameters and somehow obtains your password, it will next attempt to pull down the header text of all your incoming email from your inbox on your POP email server. On subsequent loads, only newly arrived mails are loaded, if any.

Figure 15-6.  PyMailGUI password input dialog

To save time, PyMailGUI fetches message header text only to populate the list window. The full text of messages is fetched later only when a message is selected for viewing or processing, and then only if the full text has not yet been fetched during this session. PyMailGUI reuses the load-mail tools in themailtools module of Chapter 14 to fetch message header text, which in turn uses Python’s standardpoplibmodule to retrieve your email.

>>> More Python Articles          >>> More By O'Reilly Media

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- 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

Developer Shed Affiliates


Dev Shed Tutorial Topics: