-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestemail.py
42 lines (31 loc) · 1.03 KB
/
testemail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import smtplib
from email.mime.text import MIMEText
from config import * # import SMTP details
class PushNotifier(object):
def __init__(self, host, port, user, password, fromAddr, to):
self._port = port
self._host = host
self._user = user
self._password = password
self._from = fromAddr
self._to = to
def _notify(self, subject, content):
smtp = smtplib.SMTP_SSL(self._host, self._port)
smtp.login(self._user, self._password)
text = content
msg = MIMEText(text)
msg['Subject'] = subject
msg['From'] = self._from
msg['To'] = self._to
try:
smtp.sendmail(imapUser, [self._to], msg.as_string())
finally:
smtp.close()
def onStartup(self):
self._notify('STARTED UP', 'System has started')
def onMovementDetected(self, sender, arg):
self._notify('DETECTED MOVEMENT', 'PIR detector has registered movement')
def onCarAbsent(self, sender, arg):
self._notify('CAR LEFT', 'The car is gone!!')
push = PushNotifier(imapHost, imapPort, imapUser, imapPassword, notifyEmailFrom, notifyEmailTo)
push.onStartup()