Example 14-16. PP4E\Internet\PyMailGui\altconfigs\mailconfig_train.py
from mailconfig_book import * # get base in. (copied from ..)
popusername = '[email protected]'
myaddress = '[email protected]'
listbg = 'wheat' # goldenrod, dark green, beige
listfg = 'navy' # chocolate, brown,...
viewbg = 'aquamarine'
viewfg = 'black'
wrapsz = 80
viewheaders = None # no Bcc
fetchlimit = 100 # load more headers
Example 14-17. PP4E\Internet\PyMailGui\altconfigs\launch_PyMailGui.py
to run without PYTHONPATH setup (e.g., desktop)
import os # Launcher.py is overkill
os.environ['PYTHONPATH'] = r'..........' # hmm; generalize me
os.system('PyMailGui.py') # inherits path env var
Account files like those in Examples 14-15 and 14-16 can import the base “book”
module (to extend it) or not (to replace it entirely). To use these alternative account
configurations, run a command line like the following or run the self-configuring
launcher script in Example 14-17 from any location. Either way, you can open these
account’s windows to view the included saved mails, but be sure to change configura-
tions for your own email accounts and preferences first if you wish to fetch or send mail
from these clients:
C:\...\PP4E\Internet\Email\PyMailGui\altconfigs> PyMailGui.py
Account name?rmi
Add a “start” to the beginning of this command to keep your console alive on Windows
so you can open multiple accounts (try a “&” at the end on Unix). Figure 14-45 earlier
shows the scene with all three of my accounts open in PyMailGUI. I keep them open
perpetually on my desktop, since a Load fetches just newly arrived headers no matter
how long the GUI may have sat dormant, and a Send requires nothing to be loaded at
all. While they’re open, the alternative color schemes make the accounts’ windows
distinct. A desktop shortcut to the launcher script makes opening my accounts even
easier.
As is, account names are only requested when this special PyMailGui.py file is run
directly, and not when the original file is run directly or by program launchers (in which
case there may be no stdin to read). Extending a module like mailconfig which might
be imported in multiple places this way turns out to be an interesting task (which is
largely why I don’t consider its quick solution here to be an official end-user feature).
For instance, there are other ways to allow for multiple accounts, including:
- Changing the single mailconfig module in-place
- Importing alternative modules and storing them as key “mailconfig” in sys.modules
PyMailGUI Implementation| 1115