I am having this error: 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 ij28-20020a170902ab5c00b00163efcd50bdsm1197936plb.94 - gsmtp') when I try to send a gmail in my registration app
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = '****************'
EMAIL_PORT = 587
I read in some other related forums that you just have to turn on the less secure apps in your google account settings but google already disabled that particular setting. I also tried turning off the 2-way authentication and my EMAIL_HOST_USER and EMAIL_HOST_PASSWORD are as the same as my email and password. What else should I do to solve this problem?
CodePudding user response:
i believe your problem with code, try my function, it works with gmail, without additional settings
import smtplib
from email.mime.text import MIMEText
def email_sender(to_email, theme, message):
sender = "[email protected]"
password = "mypassword"
body = message
# make up message
msg = MIMEText(body)
msg['Subject'] = theme
msg['From'] = sender
msg['To'] = ", ".join(to_email)
#sending
session = smtplib.SMTP('smtp.gmail.com', 587)
session.starttls()
session.login(sender, password)
send_it = session.sendmail(sender, to_email, msg.as_string())
session.quit()
CodePudding user response:
Thanks for the help guys. It already works by using the generated app password in my google account instead of using my own created password in EMAIL_HOST_PASSWORD