Skip to content

Instantly share code, notes, and snippets.

@pAulseperformance
Created April 11, 2019 22:37
Show Gist options
  • Save pAulseperformance/7f02951901fd10b9365992036c044bab to your computer and use it in GitHub Desktop.
Save pAulseperformance/7f02951901fd10b9365992036c044bab to your computer and use it in GitHub Desktop.
Simple Gmail Notification Function for Python standard library
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