This example was written before we had the Email Service - you may wish to modify the example to use the Email Service to send emails instead. Just enable the Email Service and replace google.mail.send with anvil.email.send (NB: if you’re on the Free Plan, stick to GMail - the Email Service sends all outgoing emails to you on the Free Plan).
Thanks for letting us know about this, it’s not explained properly in the relevant section of the docs (Integrations/Google/GMail) so I’ll improve that, and consider improving the error message too.
Thank you so much for this response! I I didn’t see google.email.send, but there is a google.mail.send in the original version. I changed over to the Email Service because I do have a paid plan, change the call to anvil.email.send, and it works like a charm!
I’m implementing the custom signup flow in an app I’m developing and I’m getting an error relating to the app origin. Is this because I have not published the app to a custom domain?
anvil.server.InternalError: Could not retrieve app files from Google. Try renewing your app file permissions in the Anvil IDE. (invalid_request; Missing required parameter: refresh_token) at /libanvil/anvil/_threaded_server.py,
line 362 called from /libanvil/anvil/server.py,
line 38 called from /libanvil/anvil/google/mail.py,
line 29 called from custom_signup/ServerModule1.py,
line 50 called from custom_signup/ServerModule1.py,
line 90 called from app/custom_signup/login_flow.py,
line 69 column 10 called from [Navigation, line 38]
The lines reference the emails that should be sent out. Here is the relevant section from ServerModule1 in my custom signup flow app.
@anvil.server.callable
def _send_password_reset(email):
"""Send a password reset email to the specified user"""
user = app_tables.users.get(email=email)
if user is not None:
user['link_key'] = mk_token()
google.mail.send(to=user['email'], subject="Нууц үгээ дахин сэргээх хэрэгтэй", text="""
Hi,
Someone has requested a password reset for your account. If this wasn't you, just delete this email.
If you do want to reset your password, click here:
%s#?email=%s&pwreset=%s
Thanks!
""" % (anvil.server.get_app_origin('published'), url_encode(user['email']), url_encode(user['link_key'])))
return True
If it helps I can setup a custom mail server as a work around until I get the domain.