Closed shechostr closed 3 years ago
Hello @shechostr,
Thank you for taking the time to report this issue!
I was not able to reproduce this locally. Following is the sample code I used:
import base64
import os
from sendgrid.helpers.mail import (
Mail, Attachment, FileContent, FileName,
FileType, Disposition)
from sendgrid import SendGridAPIClient
message = Mail(
from_email='example+from@example.com',
to_emails='example+to@example.com',
subject='Sending with Twilio SendGrid is Fun',
html_content='<strong>and easy to do anywhere, even with Python</strong>')
file_path = './text.txt'
with open(file_path, 'rb') as f:
data = f.read()
f.close()
encoded = base64.b64encode(data).decode()
attachment = Attachment()
attachment.file_content = FileContent(encoded)
attachment.file_type = FileType('plain/text')
attachment.file_name = FileName(u'{}'.format('text金.txt'))
attachment.disposition = Disposition('attachment')
message.attachment = attachment
try:
sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
response = sendgrid_client.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e.message)
Could you please provide a bit more detail to help troubleshoot?
With best regards,
Elmer
Thank you very much for your answer, I tried your Chinese file name and no problem, error email is NetEase Mail and Tencent Mail ( xx@163,com xx@qq.com) ,But google email is no problem Please try this file name "广告排期急迫.txt"
@shechostr I did try sending the email (gmail) with the suggested file name attached and I didn't see the issue. Since this is only an issue with certain email clients, this doesn't look like a library issue to me. I suggest you reach out to https://support.sendgrid.com to resolve the issue.
Add an attachment, the attachment name contains Chinese, the content of the attachment is normal after receiving the email, but the attachment name is garbled
Code Snippet
Exception/Log
The name of the attachment contains Chinese characters will be garbled
Technical details: