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