0

So I send

import smtplib

server= smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
smtp.ehlo()
server.login('mail_from@gmail.com', 'my_pass')
msg='hello'
server.sendmail('mail_from@gmail.com','mail_to@gmail.com',msg)
server.quit()

I get

File "/usr/lib/python3.7/smtplib.py", line 642, in auth raise SMTPAuthenticationError(code, resp) smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted.

Once I did this way Account -> Allow less secure app -> ON and it was OK. Recently they disabled the "Allow less secure app" feature.

Is there any way to keep sending mails?

john7
  • 123
  • 1
  • 9
  • The title of the duplicate is different but the problem is the same. – tripleee Oct 11 '22 at 07:49
  • I see no resemblance or duplication. Absolutely different problems. My problem - blocking the mail on Gmail server side by disabling 'Allow less secure app'. No matter what language you choose - Python, Java, C, C# - you'll get the same result. Till the 'Allow less secure app' problem I sent mails successfully. – john7 Oct 11 '22 at 07:57
  • Your `msg` is not a valid RFC5322 message. The "Allow less secure app" is separately a duplicate; let me find that and add it. – tripleee Oct 11 '22 at 07:58
  • May be. But it fails before server.sendmail. I fails on server.login stage. – john7 Oct 11 '22 at 07:59
  • To check it I've changed he msg - msg = EmailMessage() msg['Subject'] = 'Subject' msg['From'] = 'me' msg['To'] = 'you' The same result. – john7 Oct 11 '22 at 08:17
  • The others posts answers - enable 2-step verification - doesn't suit me. They demand my phone number to involve it in the verification. It's too much. – john7 Oct 11 '22 at 08:25

0 Answers0