Skip to content

Instantly share code, notes, and snippets.

@keyan
Last active April 9, 2021 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyan/b513346233cf37cb8d246717b9ad2144 to your computer and use it in GitHub Desktop.
Save keyan/b513346233cf37cb8d246717b9ad2144 to your computer and use it in GitHub Desktop.
Template for when you want to do something, then send an email about it
import time
import smtplib, ssl
import requests
RECEIVER_EMAIL = 'foobar@gmail.com'
def send_email(name: str):
port = 465
sender_email = "sender@gmail.com"
password = "a_password"
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
server.login(sender_email, password)
message = f"""\
Subject: EmailBot
A message {name}
"""
server.sendmail(sender_email, RECEIVER_EMAIL, message)
while True:
found = False
url = 'http://google.com'
resp = requests.get(url)
if 'some string' in str(resp.content):
continue
else:
found = True
send_email(name)
if not found:
print('Not found, sleeping...')
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment