How to fix django send mail?
<p>I'm trying to send mail in django project for several days.I've got documentation from djangoproject.com, but that's not working for me. 
my settings.py contains these lines of code for sending mail:</p>

<pre><code>EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com' 
EMAIL_PORT = 587
EMAIL_HOST_PASSWORD = '**********' #my gmail account's password 
EMAIL_HOST_USER = 'showkatalisalim@gmail.com'
</code></pre>

<p>my  views.py contains these lines for contactform:</p>

<pre><code>def contactForm(request):
    form = LocalContactForm(request.POST or None)
    if form.is_valid():
        send_mail(
'Subject here',
'Here is the message.',
settings.EMAIL_HOST_USER,
['zellaic.showkatali@gmail.com'],
fail_silently=False,
)
        return HttpResponseRedirect('thanks')
    context = {"page":"contact_form", "title":"Contact with us", "form":form}
    return render(request, 'form.html', context)
</code></pre>

<p>While I'm trying send mail via my form: It show up:</p>

<pre><code>SMTPAuthenticationError at /contact/
(534, '5.7.14 &lt;https://accounts.google.com/signin/continue?     sarp=1&amp;scc=1&amp;plt=AKgnsbtZ\n5.7.14 4CcZKxu-As7S5tfd-3YTAz6XMdwLYcJKWk7_bViejaO8v_-mx-aD8PLO5zixLUMbTv38LY\n5.7.14 qE3ifOl5aXJOXaOVN5jU9Tl-HJVDj1_bc0n9nJ4PHERsBsyu8L0JRr9rM3ED0TdFXLV3wl\n5.7.14 _GF3jCTuCHIydf-YXcFZidIIqrERHyAORvqYmuPs0qHd_rt3ecbJUBOIW9PvzOXxGBiXg2\n5.7.14 ehh9XhyakjWXfOEuJgbxiNBMdCIM0&gt; Please log in via your web browser and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 ao5sm46546625pad.1 - gsmtp')

Request Method:     POST
Request URL:    http://www.zellaic.com/contact/
Django Version:     1.10.1
Exception Type:     SMTPAuthenticationError
Exception Value:    

(534, '5.7.14 &lt;https://accounts.google.com/signin/continue?sarp=1&amp;scc=1&amp;plt=AKgnsbtZ\n5.7.14 4CcZKxu-As7S5tfd-3YTAz6XMdwLYcJKWk7_bViejaO8v_-mx-aD8PLO5zixLUMbTv38LY\n5.7.14 qE3ifOl5aXJOXaOVN5jU9Tl-HJVDj1_bc0n9nJ4PHERsBsyu8L0JRr9rM3ED0TdFXLV3wl\n5.7.14 _GF3jCTuCHIydf-YXcFZidIIqrERHyAORvqYmuPs0qHd_rt3ecbJUBOIW9PvzOXxGBiXg2\n5.7.14 ehh9XhyakjWXfOEuJgbxiNBMdCIM0&gt; Please log in via your web browser and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 ao5sm46546625pad.1 - gsmtp')

Exception Location:     /usr/lib64/python2.7/smtplib.py in login, line    621
Python Executable:  /usr/local/bin/python
Python Version:     2.7.5
Python Path:    
['/home/showkatali/webapps/zellaic/lib/python2.7/Django-1.10.1-py2.7.egg',
'/home/showkatali/webapps/zellaic',
'/home/showkatali/webapps/zellaic/src',
'/home/showkatali/webapps/zellaic/lib/python2.7',
'/home/showkatali/lib/python2.7/pip-8.1.2-py2.7.egg',
'/home/showkatali/lib/python2.7',
'/usr/lib64/python27.zip',
'/usr/lib64/python2.7',
'/usr/lib64/python2.7/plat-linux2',
'/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old',
'/usr/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7/site-packages',
'/usr/lib64/python2.7/site-packages/PIL',
'/usr/lib64/python2.7/site-packages/geos',
'/usr/lib/python2.7/site-packages']
</code></pre>

<p>And while I'm trying to use these lines into shell, It show up:</p>

<pre><code>send_mail('subject', 'sometext', settings.EMAIL_HOST_USER,   ['zellaic.showkatali@gmail.com'], fail_silently = False)
Traceback (most recent call last):
File "&lt;console&gt;", line 1, in &lt;module&gt;
File "/home/endless/Desktop/project/webfaction/env/local/lib/python2.7/site-  packages/django/core/mail/__init__.py", line 62, in send_mail
return mail.send()
File   "/home/endless/Desktop/project/webfaction/env/local/lib/python2.7/site-  packages/django/core/mail/message.py", line 342, in send
return self.get_connection(fail_silently).send_messages([self])
File  "/home/endless/Desktop/project/webfaction/env/local/lib/python2.7/site- packages/django/core/mail/backends/smtp.py", line 100, in send_messages
new_conn_created = self.open()
File   "/home/endless/Desktop/project/webfaction/env/local/lib/python2.7/site-  packages/django/core/mail/backends/smtp.py", line 67, in open
self.connection.login(self.username, self.password)
</code></pre>

<p>At this moment, What should I do? Need any configuration of my gmail account ?</p>

<p>Here is an implementation for gmail using standard <code>email</code> and <code>smtplib</code> packages (note different port and host in settings):</p>

<pre><code>//settings.py
EMAIL_HOST = 'smtp.googlemail.com' #XXX
EMAIL_PORT = 465                   #XXX
EMAIL_HOST_PASSWORD = '**********' 
EMAIL_HOST_USER = '***@gmail.com'
</code></pre>

<p>Code:</p>

<pre><code>import smtplib

from email import encoders
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate

from django.conf import settings

#send_to is a list of recipient emails
def send_mail(send_to, subject, body):

    msg = MIMEMultipart()
    msg['From'] = settings.EMAIL_HOST_USER
    msg['To'] = COMMASPACE.join(send_to)
    msg['Date'] = formatdate(localtime = True)
    msg['Subject'] = subject

    msg.attach(MIMEText(body))

    server_ssl = smtplib.SMTP_SSL(settings.EMAIL_HOST, settings.EMAIL_PORT)
    server_ssl.ehlo()
    server_ssl.login(settings.EMAIL_HOST_USER, settings.EMAIL_HOST_PASSWORD)
    server_ssl.sendmail(settings.EMAIL_HOST_USER, send_to, msg.as_string())
    server_ssl.close()
</code></pre>

python django email