-1

I found a lot of posts regarding send email with django, but I've a specific problem with gmail:

error image

here are my settings:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = "smtp.gmail.com"
EMAIL_HOST_USER = "myemail@gmail.com"
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = 'mypassword
EMAIL_PORT = 587
EMAIL_USE_TLS = True

and my view is:

from django.core.mail import EmailMessage, send_mail

    if request.method == 'POST':
        name = request.POST.get('name','')
        email = request.POST.get('email','')
        subject = request.POST.get('subject','')
        text = request.POST.get('text','')

        message = 'From: ' + email + '\n\n\n' + text

        send_mail(subject, message, 'myemail@gmail.com', ['myemail@gmail.com'], fail_silently=False)

Can you please tell me why I get this error? I also checked for google settings like "access from less secure applications" and similar

thank you in advance!!!

edit

I've already allowed less secure apps and clicked on unlock captcha

scotch
  • 171
  • 3
  • 14
  • 1
    already answered [http://stackoverflow.com/questions/26697565/django-smtpauthenticationerror](http://stackoverflow.com/questions/26697565/django-smtpauthenticationerror) – ILdar Migranov Nov 17 '16 at 17:26
  • it did not help. I've already done it... but the problem continues to be – scotch Nov 17 '16 at 17:34

2 Answers2

0

You can try this also.

import smtplib

def send_mail(request):
    try:
        subject = "Email Subject"
        description ="description"

        gmail_user =  "from@gmail.com" # email id from where you want send mail
        gmail_pwd ="password"
        FROM = 'Admin: <from@gmail.com>'
        TO = "to@gmail.com" #email id where you want send mail
        TEXT = description
        SUBJECT = subject
        server = smtplib.SMTP_SSL()
        server = smtplib.SMTP("smtp.gmail.com", 587)
        server.ehlo()
        server.starttls()

        server.login(gmail_user, gmail_pwd)
        message = """From: %s\nTo: %s\nSubject: %s\n\n%s """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
        server.sendmail(FROM, TO, message)
        server.quit()    
    except Exception,e:
        print 'exception',e
Vikram Singh Chandel
  • 1,290
  • 2
  • 17
  • 36
0

hi please check add email id without the gmail extentio ie

EMAIL_HOST_USER = "myemail"
Afsal Salim
  • 486
  • 3
  • 14