SMTPAuthenticationError - 535, b'5.7.8 Username and Password not accepted. - sending email from docker
Problem solved! I've applied different code for sending e-mail.
import smtplibimport ssldef email(request): port = settings.EMAIL_PORT smtp_server = settings.EMAIL_HOST sender_email = settings.EMAIL_HOST_USER password = settings.EMAIL_HOST_PASSWORD receiver_email = 'example@example.com' subject = 'Website registration' body = 'Activate your account.' message = 'Subject: {}\n\n{}'.format(subject, body) context = ssl.create_default_context() with smtplib.SMTP(smtp_server, port) as server: server.ehlo() # Can be omitted server.starttls(context=context) server.ehlo() # Can be omitted server.login(sender_email, password) server.sendmail(sender_email, receiver_email, message) return redirect('index')
I'm still wondering if this is the right way to pass variables from django settings. Am I doing it in elegant way and is it necessary? And is it the best way for smtp?
Another potential solution is posted here.
I used Flask but the error was exactly the same. I made sure that my credentials were correct and the environment variables were not enclosed in quotes like this post suggested.
The short answer from the first post is to click this link while logged into the google account associated with the gmail you're sending from.
Google doesn't trust most programs to automatically login to your account, so they put the onus on the owner of the gmail to give "less secure apps" permission to access your gmail.