You will need to do something like this, to read line by line:
if main_type == 'text': print("text") output_file = "" with open(attached_file, 'r') as fp: # 'rb' will send this error: 'bytes' object has no attribute 'encode' while True: cur_line = fp.readline() if cur_line == '': break output_file += cur_line.replace('\n', '\r\n') attachement = MIMEText(output_file, _subtype=sub_type)Or try this, see if it works:
if main_type == 'text': print("text") temp = open(attached_file, 'r') # 'rb' will send this error: 'bytes' object has no attribute 'encode' attachement = MIMEText(temp.read().replace('\n', '\r\n'), _subtype=sub_type) temp.close()