Home > front end >  Gmail sending problems
Gmail sending problems

Time:06-22

enter image description here

So i try smtplib to send gmail automatically, however it fail because of a error, after some checking, my username and pass are True. So i want to ask if there were any mistakes that can lead to this error.

enter image description here

Here is my code, the port is 465 and i don't want anyone know my pass and my username.

CodePudding user response:

The error message "username and password not accepted" is the standard error message you get from the smtp server when sending the users actual google password.

This method of authentication is not acceptable by the SMTP server after (May 30, 2022). Partially due to the removal of Less secure apps & your Google Account mostly because client login is not considered to be secure.

Your options are to to enable 2fa on our google account and use and create an apps password. Simply use it in place of the password in your code.

smtp.login(username, appsPasswrod)

Or to use XOauth2 and authenticate the application.

CodePudding user response:

Create a sendEmail() function, which will help to send emails to one or more than one recipient by calling the function.

def sendEmail(to, content):
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.ehlo()
    server.starttls()
    server.login('[email protected]', 'your-password')
    server.sendmail('[email protected]', to, content)
    server.close()
content = "Message to send"
to = "[email protected]"    
sendEmail(to, content)

NOTE: Do not forget to make sure that the smtplib requires 'enable the less secure apps' feature in your Gmail account. Otherwise, the sendEmail function will not work properly..

Create App Password: App Passwords

  • Related