Once pymail downloads your email to a Python list on the local client machine, you
type command letters to process it. The l command lists (prints) the contents of a given
mail number; here, we just used it to list two emails we sent in the preceding section,
with the smtpmail script, and interactively.
pymail also lets us get command help, delete messages (deletions actually occur at the
server on exit from the program), and save messages away in a local text file whose
name is listed in the mailconfig module we saw earlier:
[Pymail] Action? (i, l, d, s, m, q, ?)?
Available commands:
i - index display
l n? - list all messages (or just message n)
d n? - mark all messages for deletion (or just message n)
s n? - save all messages to a file (or just message n)
m - compose and send a new mail message
q - quit pymail
? - display this help text
[Pymail] Action? (i, l, d, s, m, q, ?) s 4
[Pymail] Action? (i, l, d, s, m, q, ?) d 4
Now, let’s pick the m mail compose option—pymail inputs the mail parts, builds mail
text with email, and ships it off with smtplib. You can separate recipients with a comma,
and use either simple “addr” or full “name
the mail is sent by SMTP, you can use arbitrary From addresses here; but again, you
generally shouldn’t do that (unless, of course, you’re trying to come up with interesting
examples for a book):
[Pymail] Action? (i, l, d, s, m, q, ?) m
From? [email protected]
To? [email protected]
Subj? Among our weapons are these
Type message text, end with line="."
Nobody Expects the Spanish Inquisition!
.
[Pymail] Action? (i, l, d, s, m, q, ?) q
To be deleted: [4]
Delete?y
Connecting...
b'+OK <[email protected]>'
Deleting messages from server...
Bye.
As mentioned, deletions really happen only on exit. When we quit pymail with the q
command, it tells us which messages are queued for deletion, and verifies the request.
Once verified, pymail finally contacts the mail server again and issues POP calls to delete
the selected mail messages. Because deletions change message numbers in the server’s
inbox, postponing deletion until exit simplifies the handling of already loaded email
(we’ll improve on this in the PyMailGUI client of the next chapter).
954 | Chapter 13: Client-Side Scripting