I'm trying to send email using smtp.gmail.com in Django project. This is my email settings.
settings.py
# Email Settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myaccount@gmail.com'
EMAIL_HOST_PASSWORD = 'mygooglepassword'
views.py
...
send_mail( "message title",
"message content",
"myaccount@gmail.com",
["myaccount@hotmail.com"],
fail_silently=False)
Whenever I try to send email, I get this error
gaierror at /contact-us/
[Errno-2] Name or service not known
I tried the followings.
- I set my google account's less secure app access on.
- I unchecked avast antivirus setting 'Setting->Protection->Core Shields->Mail Shield->Scan outbound emails(SMTP)'
- Tried different ports in email settings. 587 and 25
- Switched the ssl and tls in email settings.
But it's not sending yet. When I use 'django.core.mail.backends.console.EmailBackend' instead of 'django.core.mail.backends.smtp.EmailBackend', it prints email on console.
I double checked my gmail username and password on settings. Please help me.
Thank you.