Python Email attachment loses end-of-newline "\n" -
my python script (as following) can send ".txt" attachment, unfortunately received attachment lost "\n", lines ruined column format. can please give me help? lot!
msg['from'] = send_from msg['to'] = commaspace.join(send_to) msg['date'] = formatdate(localtime=true) msg['subject'] = 'subject of email4' mailbody = "this content of email4" msg.attach(mimetext(mailbody)) open("regresult.txt", "r") fil: part = mimeapplication( fil.read(), name=basename("regresult.txt") ) part['content-disposition'] = 'attachment; filename="%s"' % basename('regresult.txt') msg.attach(part)
update: original file (opened in remote unix server vim) this:original file format
the received file format this: received
import smtplib import io sender = 'from@fromdomain.com' receivers = ['to@todomain.com'] file = io.open('newfile.txt', 'r') message = file.readlines() try: smtpobj = smtplib.smtp('localhost') smtpobj.sendmail(sender, receivers, message) print("successfully sent email") except exception: print("error: unable send email")
Comments
Post a Comment