Learning Python Network Programming

(Sean Pound) #1
Chapter 4

Getting last message
b'Received: by 10.150.139.7 with HTTP; Tue, 7 Oct 2008 13:20:42 -0700
(PDT)'
b'Message-ID: [email protected]'
b'Date: Tue, 7 Oct 2008 21:20:42 +0100'
b'From: "Mr Person1" [email protected]'
b'To: "Mr Person2" [email protected]'
b'Subject: Re: Some subject'
b'In-Reply-To: [email protected]'
b'MIME-Version: 1.0'
b'Content-Type: multipart/alternative; '
b'\tboundary="----=_Part_63057_22732713.1223410842697"'
b'References: [email protected]'
b'\t [email protected]'
b'Delivered-To: [email protected]'
b''
b'------=_Part_63057_22732713.1223410842697'
b'Content-Type: text/plain; charset=ISO-8859-1'
b'Content-Transfer-Encoding: quoted-printable'
b'Content-Disposition: inline'
b''
b'Dear Person2,'


Retrieving e-mails by using IMAP with imaplib


As we mentioned previously, accessing e-mail over the IMAP protocol doesn't
necessarily download the message to the local computer or mobile phone. So, this
can be very efficient, even when used over any low bandwidth Internet connection.


Python provides a client-side library called imaplib, which can be used for accessing
e-mails over the IMAP protocol. This provides the IMAP4() class, which implements
the IMAP protocol. It takes two arguments, that is, host and port for implementing
this protocol. By default, 143 has been used as the port number.


The derived class, that is, IMAP4_SSL(), provides a secure version of the IMAP4
protocol. It connects over an SSL encrypted socket. So, you will need an SSL friendly
socket module. The default port is 993. Similar to POP3_SSL(), you can supply the
path to a private key and a certificate file path.

Free download pdf