Django 1.8 sending mail using gmail SMTP Django 1.8 sending mail using gmail SMTP python python

Django 1.8 sending mail using gmail SMTP


for me in settings.py:

EMAIL_USE_TLS = TrueEMAIL_HOST = 'smtp.gmail.com'EMAIL_HOST_USER = 'test@gmail.com'EMAIL_HOST_PASSWORD = 'test'EMAIL_PORT = 587

and views.py:

from django.core.mail import EmailMessageemail = EmailMessage('title', 'body', to=[email])email.send()    

and: https://accounts.google.com/DisplayUnlockCaptcha

and also make sure you turn on permission for less secure apps.


Remember to:

Go to your Google Account settings, find Security -> Account permissions -> Access for less secure apps, enable this option.

About this option: https://support.google.com/accounts/answer/6010255


I tested this and worked perfect in django 1.8:
first you should check this link, provided by google which you did :)
notice that for some strange reasons that I don't know,you have to code like this in view.py or shell:

import djangofrom django.conf import settingsfrom django.core.mail import send_mailsend_mail('Subject here', 'Here is the message.', settings.EMAIL_HOST_USER,         ['to@example.com'], fail_silently=False)

also this is my settings in setting.py file:

EMAIL_USE_TLS = TrueEMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'EMAIL_HOST = 'smtp.gmail.com'EMAIL_HOST_PASSWORD = 'xxxx' #my gmail passwordEMAIL_HOST_USER = 'xxxx@gmail.com' #my gmail usernameEMAIL_PORT = 587DEFAULT_FROM_EMAIL = EMAIL_HOST_USER