-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mailer.py
executable file
·53 lines (40 loc) · 1.45 KB
/
Mailer.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
import sys
import getpass
import platform
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_mail(teacher,course,exersise_no,files):
""" Prepares email in proper format, includes given files, uses current login as 'From' field. """
to = "mszlenk@lab011.elka.pw.edu.pl"
frm = getpass.getuser() + "@" + platform.node()
if not frm.endswith(".pw.edu.pl"):
frm += ".elka.pw.edu.pl"
msg = MIMEMultipart()
msg['Subject'] = str(exersise_no)+"@"+teacher+"@"+course
msg['To'] = to
msg['From'] = frm
for f in files:
ff = open(f,'r')
text = MIMEText(ff.read(),"plain","utf-8")
text.add_header('Content-Disposition', 'attachment', filename=f)
msg.attach(text)
s = smtplib.SMTP()
s.connect()
s.sendmail(frm,[to],msg.as_string())
if teacher=="jmyrcha":
to = "jmyrcha@lab011.elka.pw.edu.pl"
msg['To'] = to
s.sendmail(frm,[to],msg.as_string())
if teacher=="wgrabski":
to = "wgrabski@lab011.elka.pw.edu.pl"
msg['To'] = to
s.sendmail(frm,[to],msg.as_string())
print ">"+teacher+"<"
def main():
if len(sys.argv) < 5:
print "Usage",sys.argv[0],"course exersise_number teacher file1 file2 ..."
exit(1)
send_mail(sys.argv[3],sys.argv[1],int(sys.argv[2]),sys.argv[4:])
if __name__ == "__main__":
main()