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

(yzsuai) #1

New in Version 2: PyMailCGI now supports viewing and sending
Email attachments for a single user, and avoids some of the prior version's
exhaustive mail downloads. It only fetches message headers for the list page,
and only downloads the full text of the single message selected for viewing.

New in Version 3: PyMailCGI now runs on Python 3.X (only),
and employs many of the new features of the mailtools package: decoding and
encoding of Internationalized headers, decoding of main mail text, and so on.
Due to a regression in Python 3.1's cgi and email support, version 3.0 does
not support sending of binary or incompatibly-encoded text attachments, though
attachments on fetched mails can always be viewed (see Chapter 15 and 16).

Also see:


  • The PyMailGUI program in the Internet directory, which
    implements a more complete client-side Python+Tk email GUI
  • The pymail.py program in the Email directory, which
    provides a simple console command-line email interface
  • The Python imaplib module which supports the IMAP email protocol
    instead of POP





<IMG SRC="PythonPoweredSmall.gif" ALIGN=left
ALT="[Python Logo]" border=0 hspace=15>

[Book]
[O'Reilly]



The file pymailcgi.html is the system’s root page and lives in a PyMailCgi subdirectory
which is dedicated to this application and helps keep its files separate from other ex-
amples. To access this system, start your locally running web server as described in the
preceding section and then point your browser to the following URL (or do the right
thing for whatever other web server you may be using):


http://localhost:8000/pymailcgi.html

If you do, the server will ship back a page such as that captured in Figure 16-2, shown
rendered in the Google Chrome web browser client on Windows 7. I’m using Chrome
instead of Internet Explorer throughout this chapter for variety, and because it tends
to yield a concise page which shows more details legibly. Open this in your own browser
to see it live—this system is as portable as the Web, HTML, and Python-coded CGI
scripts.


Configuring PyMailCGI


Now, before you click on the “View...” link in Figure 16-2 expecting to read your own
email, I should point out that by default, PyMailCGI allows anybody to send email
from this page with the Send link (as we learned earlier, there are no passwords in
SMTP). It does not, however, allow arbitrary users on the Web to read their email


1240 | Chapter 16: The PyMailCGI Server

Free download pdf