Python3.4 send email (including attachments with Chinese characters)
Import smtplibimport osfrom email. mime. text import MIMETextfrom email. mime. multipart import MIMEMultipartfrom email import encodersuser = ********* @ qq.com 'pwd = '********' to = ['******@ 139.com ', * @ qq.com '] msg = MIMEMultipart () msg ['subobject'] =' Here is the topic... 'content1 = MIMEText ('Here is the body! ', 'Plain', 'utf-8') msg. attach (content1) attfile = 'C: \ Users \ hengli \ Pictures \ CameraMan \ haha.doc 'basename = OS. path. basename (attfile) fp = open (attfile, 'rb') att = MIMEText (fp. read (), 'base64', 'utf-8') att ["Content-Type"] = 'application/octet-stream' att. add_header ('content-disposition', 'attachment', filename = ('gbk', '', basename) encoders. encode_base64 (att) msg. attach (att) # ----------------------------------------------------------- s = smtplib. SMTP ('smtp .qq.com ') s. login (user, pwd) s. sendmail (user, to, msg. as_string () print ('sent successfully ') s. close ()