Django Mail Push solution attachment Chinese name garbled

Source: Internet
Author: User

Django Mail features, see official documentation (https://docs.djangoproject.com/en/1.10/topics/email/) for details.

Recently do this feature encountered problems, send attachments, received after the Chinese name garbled, the solution is as follows:

The file name needs to be encoded in the header, otherwise the Chinese name of the attachment will be garbled.

1   fromDjango.core.mailImportEmailmessage2   fromEmail.headerImportMake_header3   4email =emailmessage (subject, content, From_email, to)5  #file path6Address ='xxxxxxx'7Text = open (address,'RB'). Read ()8file_name =os.path.basename (address)9  #encode the name of a fileTenb = Make_header ([(File_name,'Utf-8')]. Encode ('Utf-8') One Email.attach (b, text) AEmail.send ()

The Mail service can be configured in settings.py, as follows:

1  #whether to use protocol SSL or TLS2Email_use_ssl =False3  #mail server, typically SMTP4Email_host ='smtp.xxx.com'5  #Service Port (the port that the mail delivery service corresponds to)6Email_port =XXX7  #user name and password8Email_host_user ='XXX'9Email_host_password ='xxxx'

Django Mail Push solution attachment Chinese name garbled

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.