my django app is not being able to send email. On my email less secure apps is turned on and i have unlocked captcha. am stuck i dont know what am missing. any help will be appreciated.
Traceback
Environment:
Request Method: POST
Request URL: http://localhost:8000/
Django Version: 3.0.9
Python Version: 3.8.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'shield_sec']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/base.py", 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/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/apple/projects/Django/ingabo_sec/shield_sec/views.py", line 17, in contact
send_mail (
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/mail/__init__.py", line 60, in send_mail
return mail.send()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/mail/message.py", 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/smtp.py", line 102, in send_messages
new_conn_created = self.open()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 69, in open
self.connection.login(self.username, self.password)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 734, in login
raise last_exception
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", line 723, in login
(code, resp) = self.auth(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/smtplib.py", 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 https://support.google.com/mail/?p=BadCredentials l188sm1732224lfd.127 - gsmtp')
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
# Email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '*******@gmail.com'
EMAIL_HOST_PASSWORD = '********'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
#EMAIL_USE_SSL = True
views.py
from django.shortcuts import render
from django.http import HttpResponseRedirect ,Http404
from django.core.mail import send_mail
from django.conf import settings
from . forms import ContacForm
# Create your views here.
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 (
sender_name,
sender_number,
sender_email,
['***********@gmail.com'],
sender_subject,
message,
)
return render (request,'shield_sec/contact.html', {'sender_name': sender_name})
else:
return render (request,'shield_sec/contact.html', {})
I suspecting probably there problem might lie in my settings.py but everything looks fine.