Feb-06-2018, 05:42 PM
(Feb-06-2018, 10:59 AM)lghauth Wrote: It might be because your are encoding (base64) the attachment in the line 203.
encoders.encode_base64(attachement) #https://docs.python.org/3/library/email-examples.htmlThe MIMEImage, MIMEAudio, MIMEApplication already uses base64 encoding as default. So you don't need to encode the attachment.
You will need only encode it, for MIMEBase.
So what you can try to do is change the code to this:
else: attachement = MIMEBase(main_type, sub_type) temp = open(attached_file, 'rb') attachement.set_payload(temp.read()) temp.close() #-----3.3 encode the attachment, add a header and attach it to the message encoders.encode_base64(attachement) #https://docs.python.org/3/library/email-examples.html filename = os.path.basename(attached_file)Give it a try and see if it will work now.
Removing
encoders.encode_base64(attachement) #https://docs.python.org/3/library/email-examples.htmldoes fix the issue of the text file being converted to base64, but it gives rise to another issue i.e. Notepad ignoring line breaks https://superuser.com/questions/362087/n...linebreaks The original text file doesn't have this problem, it only occurs due to the python script. Since Notepad comes with Windows as default & Windows has OS monopoly, I can't tell my colleagues to download Notepad++ to view the text file properly.