CopyCodeThe Code is as follows: #-*-coding: cp936 -*-
From email. header import Header
From email. mimetext import mimetext
From email. mimemultipart import mimemultipart
Import smtplib, datetime
# Create an instance with an attachment
MSG = mimemultipart ()
# Construct an attachment
ATT = mimetext (open ('f: \ file name .doc ', 'rb'). Read (), 'base64', 'gb2312 ')
ATT ["Content-Type"] = 'application/octet-stream'
ATT ["content-disposition"] = 'attachment; filename = "file name .doc "'
MSG. Attach (ATT)
# Add an email header
MSG ['to'] = '2017 @ QQ.com'
MSG ['from'] = '2017 @ QQ.com'
MSG ['subobject'] = header ('test ('+ STR (datetime. Date. Today () +') ', 'gb2312 ')
# Send an email
Server = smtplib. SMTP ('smtp .qq.com ')
Server. login ('20140901', '20160901 ')
Error = server. Sendmail (MSG ['from'], MSG ['to'], MSG. as_string ())
Server. Close
Print Error