Django - SendMail on Google App Engine Flexible EN

2019-08-24 13:02发布

Can anyone tell me how to configure a Django app running on Google App Engine Flexible environment to send out emails? We are trying to send confirmation emails to users (we are using django-allauth) during account/signup. Our attempts to configure App Engine for send mail is not working. We have wasted four whole days on this supposedly simple matter.

This is our current Django settings:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'my_email_address@gmail.com'
EMAIL_PASSWORD = "'********"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'my_email_address@gmail.com'

Our actual email address (replaced by 'my_email_addres@gmail.com' above) is the owner email address used to setup the App Engine instance. On App Engine Settings, we configured 'my_email_address@gmail.com' as an authorized email sender. We verified that we can successfully log into both App Engine and Gmail with our 'my_email_address' and password we provided in the Django Settings file.

However, when users attempt to signup, the sendmail step fails with the following error message (I edited the server url and email address edited below):

SMTPSenderRefused at /accounts/signup/
(530, b'5.5.1 Authentication Required. Learn more at\n5.5.1  https://support.google.com/mail/?p=WantAuthError c62sm5621898ioj.28 - gsmtp', 'my_email_address@gmail.com')
Request Method: POST
Request URL:    https://my_server_name.appspot.com/accounts/signup/
Django Version: 1.11.9
Exception Type: SMTPSenderRefused
Exception Value:    
(530, b'5.5.1 Authentication Required. Learn more at\n5.5.1  https://support.google.com/mail/?p=WantAuthError c62sm5621898ioj.28 - gsmtp', 'my_email_address@gmail.com')
Exception Location: /opt/python3.6/lib/python3.6/smtplib.py in sendmail, line 867
Python Executable:  /env/bin/python3.6
Python Version: 3.6.2

We have followed every instructions we could find online without any success. We attempted using one of our G-Suite email addresses for the sender. However, since we have not configured App Engine to use our custom domain (we are still on appspot.com), unsurprising, this did not work.

Any help? Thanks.

1条回答
来,给爷笑一个
2楼-- · 2019-08-24 13:30

The App Engine flexible environment does not have a built in mail service like the standard environment. You will need to use SendGrid, Mailgun, or Mailjet to send emails from the flexible environment.

Depending on your code/app, you might be able to configure a separate App Engine "service" to handle the requests that need to trigger the email logic from a standard environment-based subset of your app that can use the standard environment's built in mail service. App Engine apps can be a mix of services that can run on both environments and even different languages from one service to another.

Not sure that would work in your situation, but it might.

查看更多
登录 后发表回答