[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

Figure 14-14. PyMailGUI write-mail compose window


This window is much like the message view window we saw in Figure 14-5, except
there are no quick-access part buttons in the middle (this window is a new mail). It has
fields for entering header line detail, action buttons for sending the email and managing
attachment files added to it when sent, and an attached TextEditor object component
for writing and editing the main text of the new email.


The PyEdit text editor component at the bottom has no File menu in this role, but it
does have a Save button—useful for saving a draft of your mail’s text in a file. You can
cut and paste this temporary copy into a composition window later if needed to begin
composing again from scratch. PyEdit’s separate Unicode policies apply to mail text
drafts saved this way (it may ask for an encoding—see Chapter 11).


For write operations, PyMailGUI automatically fills the From line and inserts a signa-
ture text line (the last two lines shown), from your mailconfig module settings. You
can change these to any text you like in the GUI, but the defaults are filled in auto-
matically from your mailconfig. When the mail is sent, an email.utils call handles
date and time formatting in the mailtools module in Chapter 13.


There is also a new set of action buttons in the upper left here: Cancel closes the window
(if verified), and Send delivers the mail—when you press the Send button, the text you
typed into the body of this window is mailed to all the addresses you typed into the To,
Cc, and Bcc lines, after removing duplicates, and using Python’s smtplib module. Py-
MailGUI adds the header fields you type as mail header lines in the sent message
(exception: Bcc recipients receive the mail, but no header line is generated).


To send to more than one address, separate them with a comma character in header
fields, and feel free to use full “name”

pairs for recipients. In this mail, I fill
in the To header with my own email address in order to send the message to myself for


1034 | Chapter 14: The PyMailGUI Client

Free download pdf