I am trying to send email within my Django project:
# settings.py
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD')
EMAIL_PORT = 587
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
def notify_user(email_address, subject='Subject', message='Some message!') -> None:
send_mail(
subject,
message,
settings.EMAIL_HOST_USER,
[email_address],
fail_silently=False
)
As I know I need to disable this option (Gmail Security), but Gmail don't let me do it.
As a result I got this error:
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials f14-20020a056512360e00b00492bbf7db8asm320697lfs.85 - gsmtp')
What can I do? How to disable that option?
CodePudding user response:
Google disabled/discontinued the Less Secure App feature as of May 30th, 2022.
As recommended by @MeL, you could use an alternative but you can still use Gmail to send emails using Django
. You can read this blog Mail setup on django using Gmail to help with guiding the setup if you're unfamiliar with setting up Google App Passwords.
In addition to that, you'll need to do one last thing to activate the app password to be used by Django
. You should visit the site https://accounts.google.com/DisplayUnlockCaptcha, select continue and you're all set.