-
Notifications
You must be signed in to change notification settings - Fork 7
/
mail.py
39 lines (31 loc) · 875 Bytes
/
mail.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
#!/usr/bin/python
import smtplib
import sys
import os
from email.mime.text import MIMEText
arg = sys.argv
server = "mailout.privat.bahnhof.se"
class Smtp(object):
def setup(self, to, fr, message):
self.content = message
self.to = to
self.fr = fr
self.mail = MIMEText(self.content)
self.mail["Subject"] = "Airiana system has changed status."
self.mail["From"] = self.fr
self.mail["To"] = self.to
def send(self):
print("sending mail to:", self.to, "doing it from", self.fr)
print(self.content)
socket = smtplib.SMTP_SSL(server)
socket.login(os.popen("cat mailuser").read()[:-1], os.popen("cat mailpasswd").read()[:-1])
socket.sendmail(self.fr, self.to, self.mail.as_string())
socket.quit()
if __name__ == "__main__":
mail = Smtp()
if len(arg) > 2:
to = arg[1]
fr = arg[2]
content = arg[3]
mail.setup(to, fr, content)
mail.send()