#code:utf-8 import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header smtpser ...
#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()