SMTPAuthenticationError at / (535, b'5.7.8 Username and Password not accepted.

am soo frustrated at this error. for some days i have tried all possible troubleshoots(eg turning on less secure apps,2FA, unlocking captcha) still its firing the error. I will highly value your help. below is my code



Request Method: POST
Request URL: http://localhost:8000/

Django Version: 3.0.9
Python Version: 3.8.3
Installed Applications:
Installed Middleware:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/", line 34, in inner
    response = get_response(request)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/apple/projects/Django/ingabo_sec/shield_sec/", line 17, in contact
    send_mail (
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/mail/", line 60, in send_mail
    return mail.send()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/mail/", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/mail/backends/", line 102, in send_messages
    new_conn_created =
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/mail/backends/", line 69, in open
    self.connection.login(self.username, self.password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/", line 734, in login
    raise last_exception
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/", line 723, in login
    (code, resp) = self.auth(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/", line 646, in auth
    raise SMTPAuthenticationError(code, resp)

Exception Type: SMTPAuthenticationError at /
Exception Value: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 h20sm1909465lfc.239 - gsmtp')

# Email_settings 
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

def contact (request):  
    if request.method == "POST":
        sender_name = request.POST.get('sender-name',False)
        sender_number = request.POST.get('sender-number',False) 
        sender_email = request.POST.get('sender-email',False)
        sender_subject = request.POST.get('sender-subject',False)
        message = request.POST.get('message',False)

        send_mail (

        return render (request,'shield_sec/contact.html', {'sender_name': sender_name}) 
        return render (request,'shield_sec/contact.html', {})

Have you considered using an email provider such as sendgrid, mailgun, postmark, etc? This error is definitely a Google configuration/access problem. Unfortunately, I don’t have any great suggestions there.

thanks for your information. i will look up to them)

Unless you’re using a custom send_mail method, your calling sequence doesn’t match what the docs say: send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, connection=None, html_message=None).

Second, and I believe I had to confirm this in an earlier thread on this forum, GMail will not allow you to send emails from an arbitrary “from” address without authenticating / authorizing it through GMail. (Last I checked, you had to prove that you had control over the email address you’re using as the “from” address.) So, if you want emails to appear to come from something other than the account name you’re using to authenticate, you’ve got to go through the verification process for that email address.
Want to send emails from 100 different addresses? Then you would need to go through that verification process 100 times.

1 Like

thanks alot for your elaborated explanation. Fixed)