Skip to content

Instantly share code, notes, and snippets.

@ljmocic
Last active April 13, 2020 09:14
Show Gist options
  • Save ljmocic/afaf3cfe0548e5a51f586a5b7af0d7a2 to your computer and use it in GitHub Desktop.
Save ljmocic/afaf3cfe0548e5a51f586a5b7af0d7a2 to your computer and use it in GitHub Desktop.
# Read more about setting it up:
# https://medium.com/@ljmocic/send-an-email-using-python-and-gmail-4ebc980eae9b
import smtplib
from email.mime.text import MIMEText
EMAIL = ''
APP_PASSWORD = ''
RECEIVER = ''
SUBJECT = ''
MESSAGE_TEXT = ''
message = MIMEText(MESSAGE_TEXT)
message['From'] = EMAIL
message['To'] = RECEIVER
message['Subject'] = SUBJECT
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(EMAIL, APP_PASSWORD)
server.sendmail(EMAIL, RECEIVER, message.as_string())
server.close()
print('Email sent!')
except Exception as e:
print(e)
print('Something went wrong...')
@lefatoum
Copy link

Not working

@ljmocic
Copy link
Author

ljmocic commented Mar 30, 2020

It's actually working, Google changed auth for these kinds of scripts.
You can simply generate APP_PASSWORD in order to be able to send mails again.

You can find more on how to do it here: https://link.medium.com/6LbSmeu6g5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment