I am trying to send an email. The code I am using is found below:
import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart email_user = '[email protected]' email_password = 'password' email_send = '[email protected]' subject = 'subject' msg = MIMEMultipart() msg['From'] = email_user msg['To'] = email_send msg['Subject'] = subject body = 'Hi there, sending this email from Python!' msg.attach(MIMEText(body,'plain')) try: text = msg.as_string() server = smtplib.SMTP('smtp.gmail.com', port=587) server.starttls() server.login(email_user, email_password) server.sendmail(email_user,email_send,text) server.quit() print('successfully sent the mail') except: print("failed to send mail") I get an error "failed to send mail" with the error message:
SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials t10sm6451859wra.16 - gsmtp')
The error occurs on the server.login() line, I am not able to login. I checked other post and it says, it has to do with wrong credentials but my credentials are correct. I have check and double checked.
What could be the problem with this and how do I resolve it?