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

(yzsuai) #1
<a href="../pymailcgi.html">Back to root page</a>
</body></html>

The HTML reply printed by this script would normally be rendered into a new web
page if caught by a browser. Such cryptic output might be less than ideal, but you could
easily search the reply string for its components to determine the result (e.g., using the
string find method or an in membership test to look for “successful”), parse out its
components with Python’s standard html.parse or re modules (covered in
Chapter 19), and so on. The resulting mail message—viewed, for variety, with
Chapter 14’s PyMailGUI program—shows up in this book’s email account as seen in
Figure 16-6 (it’s a single text-part message).


Figure 16-6. sendurl.py result


Of course, there are other, less remote ways to send email from a client machine. For
instance, the Python smtplib module (used by mailtools) itself depends only upon the
client and SMTP server connections being operational, whereas this script also depends
on the web server machine and CGI script (requests go from client to web server to
CGI script to SMTP server). Because our CGI script supports general URLs, though, it
can do more than a mailto: HTML tag and can be invoked with urllib.request outside
the context of a running web browser. For instance, as discussed in Chapter 15, scripts
like sendurl.py can be used to invoke and test server-side programs.


Reading POP Email


So far, we’ve stepped through the path the system follows to send new mail. Let’s now
see what happens when we try to view incoming POP mail.


Reading POP Email| 1249
Free download pdf