Search code examples
pythondjangogmail

Send Email in Django From Gmail Account


In my settings.py file I have the following:

ACCOUNT_EMAIL_VERIFICATION = "none"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST_PASSWORD = "supersecretstring"
EMAIL_PORT = 587
EMAIL_USE_TLS = True

Then I run python manage.py shell And do:

from django.conf import settings
from django.core.mail import send_mail

send_mail("foo", "bar", settings.EMAIL_HOST_USER, ["[email protected]"])

Which produces this:

socket.gaierror: [Errno 8] nodename nor servname provided, or not known

I've also enabled less secure apps in my google account. What am I doing wrong?


Solution

  • Got the same error later in the night when trying to do a pip install. Rebooted the machine, and the error went away.