-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendmail.py
executable file
·65 lines (53 loc) · 1.62 KB
/
sendmail.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import smtplib
import pendulum
import json
import fire
class Mail(object):
def __init__(self):
with open('config.json') as f:
data = json.load(f)
self.address = data["mailaddress"]
self.passwd = data["mailpassword"]
self.subject = ''
self.message = ''
self.body = ''
def __send__(self):
self.body = '\r\n'.join(
['To: %s' % self.address, 'From: %s' % self.address, 'Subject: %s' % self.subject, '', self.message])
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(self.address, self.passwd)
try:
server.sendmail(self.address, self.address, self.body)
print('email sent')
except:
print('error sending mail')
server.quit()
def webcamstarted(self):
now = pendulum.now('Europe/Brussels')
date = now.ctime()
self.subject = 'Webcam-Google-Recorder Started.'
self.message = 'Webcam-Google-Recorder Started at ' + date
self.__send__()
def webcamerror(self):
now = pendulum.now('Europe/Brussels')
date = now.ctime()
self.subject = 'Webcam-Google-Recorder Error.'
self.message = 'Webcam-Google-Recorder Error at ' + date
self.__send__()
def videouplaoded(self, filename):
now = pendulum.now('Europe/Brussels')
date = now.ctime()
self.subject = 'Video ' + filename + ' uploaded.'
self.message = 'Record ' + filename + ' uploaded at ' + date
self.__send__()
def uploadfailled(self, filename):
now = pendulum.now('Europe/Brussels')
date = now.ctime()
self.subject = filename + ' upload failed.'
self.message = filename + ' upload failed at ' + date
self.__send__()
#m = Mail()
#m.webcamstarted()
if __name__ == '__main__':
fire.Fire(Mail)