Writing an email client with POP3
Now we will look into how to connect to the mail servers with POP3 to fetch an email from the email account.
Getting ready
This program requires accessing a mail account in a less secured way. Many modern email servers may block your login account. For example, you may have to make sure that access for less secure apps has been turned on.
How to do it...
You need to offer a valid email address and password to send an email through this recipe. We pass the email server, POP3 port
, user
and password
as the arguments, and receive the password to your email account using the getpass
library (so that your email password is not displayed in plain text).
Listing 5.11 gives the simple POP3 email client as follows:
#!/usr/bin/env python # Python Network Programming Cookbook, Second Edition -- Chapter - 5 # This program is optimized for Python 2.7.12 and Python 3.5.2. # It may run on any other version with/without modifications. import getpass import poplib import...