Friday, 23 August 2013

emailing content of a text file on unix platform

emailing content of a text file on unix platform

I am using the following piece of code to email the content of gerrit.txt
but its not working?it doesnt show any errors but doesnt work the way its
supposed to.any inputs on how to fix this?
from email.mime.text import MIMEText
from subprocess import check_call,Popen,PIPE
def email (body,subject,to=None):
msg = MIMEText("%s" % body)
msg['Content-Type'] = "text/html;"
msg["From"] = "userid@company.com"
if to!=None:
to=to.strip()
msg["To"] = "userid@company.com"
else:
msg["To"] = "userid@company.com"
msg["Subject"] = '%s' % subject
p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
def main ():
Subject ="test email"
email('gerrit.txt',Subject,'userid')
if __name__ == '__main__':
main()

No comments:

Post a Comment