I have an xls file which has few images and graphs in it. I would like to attach this file and send to an email. Below is my code:
def create_message(report):
message = MIMEMultipart()
message['From'] = msettings.EMAILS_SEND_FROM_NAME
message['To'] = msettings.EMAILS_SEND_TO
message['Subject'] = msettings.EMAILS_SUBJECT
with open(report, "r") as file:
payload = MIMEApplication(file.read(), Name=os.path.basename(report))
content = 'attachment; filename="{}"'.format(os.path.basename(report))
payload['Content-Disposition'] = content
message.attach(payload)
But I get the following Error
message = create_message(file)
line 148, in create_message
payload = MIMEApplication(file.read(), Name=os.path.basename(report))
File "python-3.4.3\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 732: character maps to <undefined>
I doubt that the encoding of my xls file is not supported. How can I attach a xls file with images,graphs and a lot of formatting as an attachment without losing any information from the xls file?