Reputation: 4783
I'm currently reading a book on Django (for beginners) and I reached the point where I need to implement a password reset feature to the test website using SendGrid SMTP Relay.
After creating an account and starting to create the SMTP relay I greeted with the following screen:
Based on this page I added the following lines of code to my setting.py file:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = 'xxxxx' #the string which is partialy hidden under the pink square
EMAIL_PORT = 587
EMAIL_USE_TLS = True
After running the website and trying to reset my password (the password of the superuser) I get the desired message with the reset link in my console but sadly nothing comes to my email. Thus I get the following error message when trying to verify integration.
What I tried so far:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
from the settings.py
file (this only made things worst)I've been trying to solve this issue for over a day now, any help would be greatly appreciated!
Upvotes: 3
Views: 1181
Reputation: 20702
Your email backend setting is set to use the console. If you're just debugging that's fine, you can see how the emails would look like in the console and copy your password reset link from there.
If you really want to send an email, use the SMTP backend: Set EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
.
But beware, don't send emails to fake addresses using that, you'll get in trouble if you have too many bounces on your sendgrid account.
Also if you're going to use SendGrid in production, use the API instead of SMTP. django-anymail (but there are also other packages) provides a backend to use the API.
Update June 2021 Sendgrid doesn't allow simple username/password authentication anymore (and forces you to login with 2FA). You should use the API, or create an app password specifically for your server and use that instead of your normal password.
Upvotes: 5
Reputation: 73
I'd say the settings are like they should be, taking into account that you of course don't intend to go into production without securing your info (ie creating environment variables). You are going to do this, I assume, but if not, you really, really should consider that.
Also it's these are your actual settings, you should edit this post right now. They're supposed to be kept secret, otherwise you're gonna have a real bad day shortly.
Given the nature of your problem, I'm halfway expecting that you're not testing it from a development setting, but rather that you've tried to run it from production. It is also my suspicion, that you're using Pythonanywhere or Heroku with a free account. Let me know if I'm all wrong here :)
The skinny is this: Without coughing up those $5, those two providers (and other providers add well, I presume) won't let you use sendgrid.
If I'm assuming wrongly, I'd appreciate seeing the views.py that handles the sending of email.
Upvotes: 0