#code:utf-8
import smtplib from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
smtpserver = ‘smtp.163.com‘
smtp_user = ‘*******‘
smtp_pass = ‘*******‘
from_addr=‘**********@163.com‘
to_addr= ‘********@qq.com‘
subject = ‘休假申请‘
#message = MIMEMultipart()
message = MIMEText(‘这是今天的休假申请‘,‘plain‘,‘utf-8‘)
message[‘Subject‘] = Header(subject,‘utf-8‘)
message[‘From‘] = from_addr
message[‘To‘] = to_addr
#注释部分为带附件的代码
#message.attach(message_text)
#att1=MIMEText(open(‘test.txt‘,‘rb‘).read(),‘base64‘,‘utf-8‘)
#att1[‘Content-Type‘] = ‘application/octet-stream‘
#att1[‘Content-Disposition‘] = ‘attachment:filename="test.txt"‘
#message.attach(att1)
sm=smtplib.SMTP()
sm.connect(smtpserver,25)
sm.login(smtp_user,smtp_pass)
sm.sendmail(from_addr,to_addr,message.as_string())
sm.quit()