Python Network Programming
by Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
How it works...
This recipe downloads a user's first Google message via POP3. The download_email() method creates a mailbox object with Python, the POP3_SSL() class of poplib. We passed the Google POP3 server and port address to the class constructor. The mailbox object then sets up a user account with the user() method call. The password is collected from the user securely using the getpass module's getpass() method and then passed to the mailbox object. The mailbox's list() method gives us the email messages as a Python list.
This script first displays the number of email messages stored in the mailbox and retrieves the first message with the retr() method call. Finally, it's safe to call the quit() method on the mailbox to clean up the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access