Skip to content

Instantly share code, notes, and snippets.

@spellancer
Last active August 29, 2015 13:57
Show Gist options
  • Save spellancer/9461736 to your computer and use it in GitHub Desktop.
Save spellancer/9461736 to your computer and use it in GitHub Desktop.
Email_alert
import smtplib
import sys
from email.mime.text import MIMEText
def mail(motion,smoke):
me = '[email protected]'
you = ['[email protected]', '[email protected]','[email protected]']
smtp_server = 'smtp.gmail.com:587'
if motion and smoke:
msg = MIMEText('Motion and smoke detected! Intruder detected, FIRE ALARM!!!')
msg['Subject'] = 'Motion & Fire ALERT from home'
elif smoke:
msg = MIMEText('Smoke detected!, FIRE ALARM!!!')
msg['Subject'] = 'Fire ALERT from home'
elif motion:
msg = MIMEText('Motion sensor caught movemenet, Intruder detected!!!')
msg['Subject'] = 'Motion ALERT from home'
msg['From'] = me
msg['To'] = ','.join(you)
username = 'username'
password = 'password'
s = smtplib.SMTP(smtp_server)
#s.set_debuglevel(1)
s.starttls()
try:
s.login(username,password)
s.sendmail(me, you, msg.as_string())
return 1
except:
return 0
s.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment