A PyMailGUI Demo - Loading Mail (
Page 2 of 4 )
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 the
mailconfig
module, PyMailGUI
loads the password from that file as needed.
Popup dialog
If you don’t put a password filename in
mailconfig
(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—a
show='*'
option for the
Entry
field used in this popup tells Tkinter to echo typed characters as stars (this option is similar in spirit to both the
getpass
console input module we met earlier in the prior chapter, and an HTML
type=password
option 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 in
mailconfig
if 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 the
mailtools
module of Chapter 14 to fetch message header text, which in turn uses Python’s standard
poplib
module to retrieve your email.