Stranger6667 / postmarker

Python client library for Postmark API
https://postmarker.readthedocs.io/en/stable/
MIT License
134 stars 29 forks source link

Cant attach csv file with UTF-8 #189

Open dogrocker opened 4 years ago

dogrocker commented 4 years ago

Hello, I attach csv file with unicode string and send to email with postmark. When I download csv file and open with ms excel the file show wrong string. Not sure what I do wrong ?

        files = []
        csvfile = StringIO()
        writer = csv.writer(csvfile)
        writer.writerow(['some unicode string'])

        data = csvfile.getvalue()
        attachment = MIMEBase('text', 'csv')
        attachment.set_payload(data.encode('utf-8'))
        encoders.encode_base64(attachment)
        attachment.add_header('Content-Disposition', 'attachment', filename='readme.csv')
        files.append(attachment)

        email = postmark.emails.send_with_template(
            TemplateId=xxx,
            TemplateModel={},
            From='no-reply@mail.com',
            To=['mymail@mail.com'],
            Attachments=files
        )
bogdan-calapod commented 3 years ago

How are you opening the CSV file in Excel ?

Excel is pretty picky about how it opens CSV files - the safest way is to use the Import Data feature, instead of double-clicking the file.