Skip to content

Instantly share code, notes, and snippets.

@christianmondabon
Last active May 8, 2018 14:38
Show Gist options
  • Save christianmondabon/582655ed2fc41a2c129d0fc4e55ea8c5 to your computer and use it in GitHub Desktop.
Save christianmondabon/582655ed2fc41a2c129d0fc4e55ea8c5 to your computer and use it in GitHub Desktop.
Send E-Mail with a Python script
import smtplib
import ssl
from email.mime.text import MIMEText
# Create message
message = MIMEText("TEXT")
message['Subject'] = "SUBJECT"
message['From'] = "YOUR GMAIL ADDRESS"
message['To'] = "RECIPIENT EMAIL ADDRESS"
# Send message
try:
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
smtpconnection = smtplib.SMTP(host='smtp.gmail.com', port=587)
smtpconnection.ehlo()
smtpconnection.starttls(context=context)
smtpconnection.ehlo()
smtpconnection.login(message['From'], "PASSWORD")
smtpconnection.send_message(message)
smtpconnection.quit()
print ("Successfully sent email")
except Exception as e:
print (str(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment