ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

Issue on using frappe.sendmail to send email with attachment

HI

When I use frappe.sendmail in my app, I noticed that the name of attachment shows incorrect if it is non-english like below.
image
The raw content of email shows like that.
Content-Disposition: attachment; filename=“中文附件-测试.zip”

I tested just use email client to send that attachment which shows correct filename,
the raw content is like that.
Content-disposition: attachment;
filename*=UTF-8’’%E4%B8%AD%E6%96%87%E9%99%84%E4%BB%B6-%E6%B5%8B%E8%AF%95.zip

So my question is how to use sendmail to fix that issue.
Thank you.

I noticed the python code in frappe/frappe/email_body.py controls the filename of attachments.

   358          # Set the filename parameter
   359          if fname:
   360                  attachment_type = 'inline' if inline else 'attachment'
   361                  part.add_header('Content-Disposition', attachment_type, filename=text_type(fname))
   362          if content_id:
   363                  part.add_header('Content-ID', '<{0}>'.format(content_id))
   364  
   365          parent.attach(part)

i’m thinking if add utf-8 encode for fname, that may fix the issue.

Thanks.