Feb-07-2018, 01:51 PM
By default when you open a file in text mode, Python 3 will convert all "newlines" to "\n" and Windows uses "\r\n". Thats
why you are having this issue.
From Python documentation https://docs.python.org/3/tutorial/input...ting-files
In text mode, the default when reading is to convert platform-specific line endings (\n on Unix, \r\n on Windows) to just \n.
To fix you have 2 options, you can try to read line by line (by using readline) and add "\r\n" in the end of each line.
Or you can try to open the Text File in binary mode:
why you are having this issue.
From Python documentation https://docs.python.org/3/tutorial/input...ting-files
In text mode, the default when reading is to convert platform-specific line endings (\n on Unix, \r\n on Windows) to just \n.
To fix you have 2 options, you can try to read line by line (by using readline) and add "\r\n" in the end of each line.
Or you can try to open the Text File in binary mode:
if main_type == 'text': print("text") temp = open(attached_file, 'rb') # 'rb' will send this error: 'bytes' object has no attribute 'encode' attachement = MIMEText(temp.read(), _subtype=sub_type) temp.close()I didn't test the solution above, but you can give a try and see if it Works.