Last active
May 8, 2018 14:38
-
-
Save christianmondabon/582655ed2fc41a2c129d0fc4e55ea8c5 to your computer and use it in GitHub Desktop.
Send E-Mail with a Python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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