Last active
August 29, 2015 13:57
-
-
Save spellancer/9461736 to your computer and use it in GitHub Desktop.
Email_alert
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 | |
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