问题
When sending an email on heroku I get this error:
No module named 'sendgrid_backend'
I have this set up in settings.py:
EMAIL_BACKEND = "sendgrid_backend.SendgridBackend"
SENDGRID_API_KEY = os.environ.get("SENDGRID_API_KEY")
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = os.environ.get('SENDGRID_API_KEY')
I also did install of sendgrid using pip and included it in the requirements.txt
回答1:
I think this will help you First, install the package
pip install sendgrid-django
and then create requirements.txt, email backend should be like this
EMAIL_BACKEND = "sgbackend.SendGridBackend"
or you can also do this
pip install django-sendgrid-v5
# https://github.com/sklarsa/django-sendgrid-v5
EMAIL_BACKEND = 'sendgrid_backend.SendgridBackend'
SENDGRID_API_KEY = '<SENDGRID_API_KEY>'
I think you should follow this
回答2:
After some tinkering around, this worked for me:
SENDGRID_API_KEY = os.environ.get("SENDGRID_API_KEY")
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'your sendgrid user name'
EMAIL_HOST_PASSWORD = 'your sendgrid password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'your sendgrid email'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
来源:https://stackoverflow.com/questions/60014049/no-module-named-sendgrid-backend-in-django