I'm using web2py 2.22.3. My only email settings in db.py are are:
## configure email
mail=auth.settings.mailer
mail.settings.server = '
smtp.gmail.com:587'
mail.settings.sender = '********@
gmail.com'
mail.settings.login = '********@gmail.com:################'
The length 16 password is the app password generated by gmail. Emails work, used mainly by auth to send
reset-password links.
Here's a little python snippet to test your userid / password work with gmail.
import imaplib
import sys
def checkGmail(userid, password):
'''
get unread email count and spam count from gmail
'''
try:
session = imaplib.IMAP4_SSL('
imap.gmail.com')
session.login(userid, password)
session.select()
unseen_inbox = len(session.search(None, 'UNSEEN')[1][0].split())
rc = session.select('[Gmail]/Spam')
if rc[0] == 'OK':
spam = int(rc[1][0])
else:
spam = '0'
return(True, unseen_inbox, spam)
except:
print(("Unexpected error:", sys.exc_info()))
return (False,)
if __name__ == '__main__':
print (checkGmail('**********@
gmail.com', '################'))
When I run this with the userid and password set in my db.py file I get (True, 30, 5), demonstrating that I can log in to gmail with the userid and app password. Does it work for you?