15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

...<br />

p.quit()<br />

Before we take a look at a real example, let's take a look at an interactive example as well as introduce<br />

the basic methods of the poplib.POP3 class.<br />

17.4.10. Interactive POP3 Example<br />

Here is an interactive example of using <strong>Python</strong>'s poplib:<br />

>>> from poplib import POP3<br />

>>> p = POP3('pop.python.is.cool')<br />

>>> p.user('techNstuff4U')<br />

'+OK'<br />

>>> p.pass_('notMyPasswd')<br />

Traceback (most recent call last):<br />

File "", line 1, in ?<br />

File "/usr/local/lib/python2.4/poplib.py", line 202,<br />

in pass_<br />

return self._shortcmd('PASS %s' % pswd)<br />

File "/usr/local/lib/python2.4/poplib.py", line 165,<br />

in _shortcmd<br />

return self._getresp()<br />

File "/usr/local/lib/python2.4/poplib.py", line 141,<br />

in _getresp<br />

raise error_proto(resp)<br />

poplib.error_proto: -ERR directory status: BAD PASSWORD<br />

>>> p.user('techNstuff4U')<br />

'+OK'<br />

>>> p.pass_('youllNeverGuess')<br />

'+OK ready'<br />

>>> p.stat()<br />

(102, 2023455)<br />

>>> rsp, msg, siz = p.retr(102)<br />

>>> rsp, siz<br />

('+OK', 480)<br />

>>> for eachLine in msg:<br />

... print eachLine<br />

...<br />

Date: Mon, 26 Dec 2005 23:58:38 +0000 (GMT)<br />

Received: from c-42-32-25-43.smtp.python.is.cool<br />

by python.is.cool (scmrch31) with ESMTP<br />

id ; Mon, 26 Dec 2005<br />

23:58:37 +0000<br />

From: wesley@python.is.cool<br />

To: wesley@python.is.cool<br />

Subject: test msg<br />

xxx<br />

.<br />

>>> p.quit()<br />

'+OK python.is.cool'

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!