import smtplib # creates SMTP session s = smtplib.SMTP('smtp.gmail.com', 587) # start TLS for security s.starttls() # Authentication s.login("email-id", "password") # message to be sent message = "message sent using python" # sending the mail s.sendmail("senders_email_id", "recievers_email_id", message) # terminating the session s.quit()
Copy and paste your password to ensure there are no typos. Don't think too highly of yourself to believe you are incapable of making this mistake! Additionally, if you are using 2-factor authentication, you will be required to use application-specific passwords instead of your normal password.
If you are not using 2-factor authentication and you have verified the credentials in your Python source are correct, follow these steps:
- Login to gmail in your browser
- Navigate to the DisplayUnclockCaptcha page.
Click the continue button, and you will see the message
Account access enabled Please try signing in to your Google account again from your new device or application.
Run your Python script - your login attempt should be successful.