1 #!/usr/bin/env python3
2 #coding: utf-8
3 import smtplib
4 from email.mime.text import MIMEText
5 from email.header import Header
6 sender = '***'
7 receiver = '***'
8 subject = 'python email test'
9 smtpserver = 'smtp.163.com'
10 username = '***'
11 password = '***'
12
13 msg = MIMEText('你好','text','utf-8')
14 msg['Subject'] = Header(subject, 'utf-8')
15
16 smtp = smtplib.SMTP()
17 smtp.connect('smtp.163.com')
18 smtp.ehlo()
19 smtp.starttls()
20 smtp.ehlo()
21 smtp.set_debuglevel(1)
22 smtp.login(username, password)
23 smtp.sendmail(sender, receiver, msg.as_string())
24 smtp.quit()