Created
September 19, 2016 18:16
-
-
Save krishna209/81834606ca8a9c26f9123a3300772280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat mail.py | |
import os | |
import sys | |
missing_list = sys.argv[1] | |
f = open('/home/kkadigar/krish/missingfiles.html','ab') | |
header=""" | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
h1 { | |
font-size: 250%; | |
font-family: Calibri, sans-serif; | |
} | |
h2 { | |
font-size: 200%; | |
font-family: Calibri, sans-serif; | |
} | |
p { | |
font-size: 100%; | |
font-family: Calibri, sans-serif; | |
color: black; | |
} | |
</style> | |
</head> | |
<body> | |
<h1></h1> | |
<h2></h2> | |
<p><b>Missing files in the directory are listed below</b></p>""" | |
body=""" | |
<table style="width:85%"> | |
<style> | |
table, th, td { | |
border: 1px solid black; | |
border-collapse: collapse; | |
padding-left: 8px; | |
padding-right: 8px; | |
font-family: Calibri, sans-serif; | |
font-size: 13px; | |
} caption { | |
font-family: Calibri, sans-serif; | |
font-size: 13px; | |
} | |
</style> | |
<caption><b>Missing Files</b></caption> | |
<tr> | |
<th align = "left">Serial No</th> | |
<th align = "left">File Name</th> | |
</tr> | |
""" | |
f.write(header) | |
f.write(body) | |
count=1 | |
with open('%s' % missing_list,'r') as data: | |
for line in data: | |
lines = """<tr><td>%d"""%(count,)+"""</td> <td>"""+line+"""</td></tr>""" | |
f.write(lines) | |
count=count+1 | |
#data = open('/home/kkadigar/krish/file','r') | |
#while data.readline(): | |
# lines = """<tr><td>%d"""%(count,)+"""</td> <td>"""+data.readline()+"""</td></tr>""" | |
# f.write(lines) | |
# count=count+1 | |
#data.close() | |
end=""" | |
</table> | |
</body> | |
</html>""" | |
f.write(end) | |
f.close() | |
os.chmod('/home/kkadigar/krish/missingfiles.html',0777) | |
import smtplib | |
from email.mime.text import MIMEText | |
from email.mime.multipart import MIMEMultipart | |
htmlfile='/home/kkadigar/krish/missingfiles.html' | |
fp = open(htmlfile,'rb') | |
msg = MIMEText(fp.read(),'html') | |
fp.close() | |
msg['Subject'] = 'Missing files are listed below' | |
msg['From'] = '[email protected]' | |
msg['To'] = '[email protected]' | |
s = smtplib.SMTP('localhost') | |
s.sendmail('[email protected]',['[email protected]'],msg.as_string()) | |
s.quit() | |
os.remove('/home/kkadigar/krish/missingfiles.html') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment