import smtplib
from email.mime.text import MIMEText
SMTPserver = 'smtp.163.com' #邮箱服务器
sender = 'qaqzz5123@163.com' #发送邮箱
password = "hlx951118nb" #密码
message = 'I send a message by Python. 你好'
msg = MIMEText(message)
msg['Subject'] = 'Test Email by Python'
msg['From'] = 'sender'
msg['To'] = 'destination'
mailserver = smtplib.SMTP(SMTPserver, 25)
mailserver.login(sender, password)
mailserver.sendmail(sender, [sender], msg.as_string())
mailserver.quit()
print ('send email success') |