Created
April 11, 2019 22:37
-
-
Save pAulseperformance/7f02951901fd10b9365992036c044bab to your computer and use it in GitHub Desktop.
Simple Gmail Notification Function for Python standard library
This file contains hidden or 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, ssl | |
import settings | |
message = """\ | |
Subject: Here I am. | |
This message was sent from Python.""" | |
def send_gmail(message): | |
port = 465 # For SSL | |
smtp_server = "smtp.gmail.com" | |
sender_email = settings.SENDER_EMAIL | |
password = settings.SENDER_PASSWORD | |
receiver_email = settings.RECIEVER_EMAIL | |
context = ssl.create_default_context() | |
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server: | |
server.login(sender_email, password) | |
server.sendmail(sender_email, receiver_email, message) | |
if __name__ == "__main__": | |
send_gmail(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment