sending an email with attachment using python script -
i'm using code given in tutorialspoint.com sending email attatchment. code works fine , i'm recieving emails problem when upload text file looks this:
|checks| |status| |remarks| echconnect checked model connected echpenetra checked echpenet: 2436 elements penetrate/touch each other echcharlen not_checked echcoincid checked no coincident elements echedgelen checked shortest edge length = 1. emsamenorm checked no elements have reoriented eebeam checked 34 elements modified according window settings outline checked free edges displayed in green
the text file recieve pretty messed indentation. want similar this. how can that? code used follows:
#!/usr/bin/python import smtplib import base64 filename = "/home/hamanda/desktop/transfer/new_result.txt" # read file , encode base64 format fo = open(filename, "rb") filecontent = fo.read() encodedcontent = base64.b64encode(filecontent) sender = 'harisyam.manda@daimler.com' reciever ='harisyam.manda@daimler.com' marker = "auniquemarker" body =""" test email send attachement. """ # define main headers. part1 = """from: person <harisyam.manda@daimler.com> to: person <harisyam.manda@daimler.com> subject: sending attachement mime-version: 1.0 content-type: multipart/mixed; boundary=%s --%s """ % (marker, marker) # define message action part2 = """content-type: text/plain content-transfer-encoding:8bit %s --%s """ % (body,marker) # define attachment section part3 = """content-type: multipart/mixed; name=\"%s\" content-transfer-encoding:base64 content-disposition: attachment; filename=%s %s --%s-- """ %(filename, filename, filecontent, marker) message = part1 + part2 + part3 try: smtpobj = smtplib.smtp('localhost') smtpobj.sendmail(sender, reciever, message) print "successfully sent email" except exception: print "error: unable send email"
Comments
Post a Comment