auth on GAE 'unable to send email'

56 views
Skip to first unread message

David Manns

unread,
Jan 6, 2017, 6:51:16 PM1/6/17
to web2py-users
Running 2.14.6 in production on GAE. Notice can't send the verification's so can't register or recover passwords. (have another problem with lost passwords which reported separately).

Using all the standard setup to initialize auth.settings.mailer in db.py AND that same auth.settings.mailer is used elsewhere to send out regular emails, which works fine!

in db.py:

mail = auth.settings.mailer
if request.env.web2py_runtime_gae:            # if running on Google App Engine
    mail.settings.server = 'gae'
    mail.settings.login = None              # your credentials or None
else:    # development environment with Web2py alone
    mail.settings.server = myconf.get('smtp.server')
    mail.settings.login = myconf.get('smtp.login')
mail.settings.sender = myconf.get('smtp.sender')
mail.settings.tls = myconf.get('smtp.tls') or False
mail.settings.ssl = myconf.get('smtp.ssl') or False

# -------------------------------------------------------------------------
# configure auth policy
# -------------------------------------------------------------------------
auth.settings.create_user_groups = False
auth.settings.mailer = mail                    # for user email verification
auth.settings.registration_requires_verification = True
auth.messages.verify_email = u'Click on the link http://'+request.env.http_host+URL('default','user',args=['verify_email'])+'/%(key)s to verify your email'
auth.settings.reset_password_requires_verification = True
auth.messages.reset_password = u'Click on the link http://'+request.env.http_host+URL('default','user',args=['reset_password'])+'/%(key)s to reset your password'
#auth.settings.registration_requires_verification = True
auth.settings.registration_requires_approval = False
#auth.settings.reset_password_requires_verification = True
,,,

in appconfig.ini:

[smtp]
server = smtp.gmail.com:587
sender = "Oxford & Cambridge Society" <email address>
login  = <username>:<password>
tls    = true
ssl    = false

As an aside, I originally had ssl =true but this caused unreliable message delivery in the web2py development environment. Adding the unicode indicator to the auth.message. settings made no difference.

David Manns

unread,
Jan 7, 2017, 12:04:32 PM1/7/17
to web2py-users
By playing with earlier versions, I established that 2.12.3 did not seem to have this problem. The problem was in both earlier and later versions. Don't know if 2.12.3 was the only version without the problem.

Leonel Câmara

unread,
Jan 9, 2017, 1:18:27 PM1/9/17
to web2py-users
This is not a problem with web2py, this is a problem with gmail SMTP which doesn't allow normal SMTP protocol anymore unless you allow what they call "insecure apps".

See:

David Manns

unread,
Jan 9, 2017, 6:10:31 PM1/9/17
to web2py-users
I don't agree. Other emails from elsewhere using mail.send() in the application go out just fine. This despite the 'allow insecure apps' option being off on the email account used. Only the emails generated by the auth() registration and password reset processes are affected. There must be something different about auth()'s usage of email causing the problem.

I tried turning on 'allow insecure apps' and it made not difference.

Also, if I run with old version built with web2py 2.12.3, this problem goes away. (Though there was still a problem with password reset that I documented here: https://groups.google.com/forum/#!topic/web2py/QBs3esYnH6w

Leonel Câmara

unread,
Jan 10, 2017, 10:11:19 AM1/10/17
to web2py-users
There's nothing different about the way Auth sends emails. Nothing. The most likely cause then, given that you can send emails in other places, is that your email message bodies such as auth.messages.verify_email have some mistake in them, causing Mail.send to get an exception, Mail.send has everything inside a Try/Except but it does log the error as "Mail.send failure:YOUR_ERROR_HERE". I suggest you check the log.
Reply all
Reply to author
Forward
0 new messages