I am facing a problem when trying to test sending a message from the django app, but I get this error message :
SMTPAuthenticationError at /accounts/contact_us
(535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8
https://support.google.com/mail/?p=BadCredentials f13sm16175910wrt.86 -
gsmtp')
And I looked for all the possible solutions like : Enable two-step verification , Enable less secure app access settings . But it was in vain and did not work successfully. Could anyone help please ?
this is my settings :
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myname@gmail.com'
EMAIL_HOST_PASSWORD = '****************'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
this is my views.py:
def contact_us(requset):
subject = requset.POST.get('subject', '')
message = requset.POST.get('message', '')
from_email = requset.POST.get('from_email', '')
send_mail(subject, message, from_email, ['myname@gmail.com'])
return render( requset , 'accounts/contact_us.html' )
this is my contact_us.html:
<div class="contact_form">
<form name="contact_form" action="" method="POST">
{% csrf_token %}
<p><input type="text" name="subject" class="name" placeholder="subject" required></p>
<p><textarea name="message" class="message" placeholder="message" required></textare></p>
<p><input type="text" name="from_email" class="email" placeholder="email" required></p>
<p><input type="submit" value="sent" class="submit_btn"></p>
</form>
</div>