-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailSummary.py
More file actions
59 lines (47 loc) · 1.58 KB
/
EmailSummary.py
File metadata and controls
59 lines (47 loc) · 1.58 KB
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
import smtplib
import config
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def sendEmailSummary(smallFiles, bigFiles):
""" Sends an email summary of all small files and all big files. """
if not smallFiles and not bigFiles:
raise Exception("You must send a list of either small files or big files or both")
msg = MIMEMultipart('alternative')
msg['Subject'] = "File sort summary"
msg['From'] = config.sender
msg['To'] = config.receiver
textMessage = """ \
Files sent to Movies:
{0}
Files sent to Series:
{1}
""".format('\n'.join(bigFiles), '\n'.join(smallFiles))
movieFileSection = "<ul>"
for bigFile in bigFiles:
movieFileSection += "<li>{0}</li>".format(bigFile)
movieFileSection += "</ul>"
seriesFileSection = "<ul>"
for smallFile in smallFiles:
seriesFileSection += "<li>{0}</li>".format(smallFile)
seriesFileSection += "</ul>"
htmlMessage = """ \
<html>
<head></head>
<body>
<h2>Files sent to Movies:</h2>
{0}
<h2>Files sent to Series:</h2>
{1}
</body>
</html>
""".format(movieFileSection, seriesFileSection)
part1 = MIMEText(textMessage, 'plain')
part2 = MIMEText(htmlMessage, 'html')
msg.attach(part1)
msg.attach(part2)
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
server.login(config.username, config.password)
server.sendmail(config.sender, config.receiver, msg.as_string())
#smallFiles = ["first.mkv", "second.mkv"]
#bigFiles = ["big1.mkv", "big2.avi"]
#sendEmailSummary(smallFiles, bigFiles)