So I'm trying to access gmail with POP using a simple script, almost the exact same as found here Checking email with Python except with the username and password taken from a secrets file.
import poplib
from email import parser
from secrets import *
pop_conn = poplib.POP3_SSL('pop.gmail.com')
pop_conn.user(username)
pop_conn.pass_(password)
#Get messages from server:
messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
# Concat message pieces:
messages = ["\n".join(mssg[1]) for mssg in messages]
#Parse message into an email object:
messages = [parser.Parser().parsestr(mssg) for mssg in messages]
for message in messages:
print message['subject']
pop_conn.quit()
However, this produces the following error:
Traceback (most recent call last):
File "checkmail.py", line 7, in <module>
pop_conn.pass_(password)
File "/usr/lib/python2.7/poplib.py", line 197, in pass_
return self._shortcmd('PASS %s' % pswd)
File "/usr/lib/python2.7/poplib.py", line 160, in _shortcmd
return self._getresp()
File "/usr/lib/python2.7/poplib.py", line 136, in _getresp
raise error_proto(resp)
poplib.error_proto: -ERR [AUTH] Web login required: https://support.google.com/mail/answer/78754
Reading the link, as well as an email Google sent, explains that they blocked access from this script based on security grounds. It is possible to disable this security, but I'd rather not. So my question is, how can I go about making this script pass the security checks.
Cheers for any help.