Establishing a connection with Gmail for reading emails 

Now, we are going to go into detail regarding the code of the previous script. For reading, we first establish the connection to the Gmail pop server, using the getpass module to request the password:

# Connection is established with the gmail pop server
mailbox = poplib.POP3_SSL ('pop.gmail.com', 995)

import getpass
username = input('Enter your username:')
password = getpass.getpass(prompt='Enter your password:')

mailbox.user(username)
mailbox.pass_(password)

Here, we used poplib.POP3_SSL, passing the name of the server, that is, pop.gmail.com, and the connection port, 995. Then, we have set the username and password of Gmail. The method to do this is pass_(), with an underscore at the end.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset