python发送邮件功能


#coding: utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header

sender = 'xxx@163.com'
receiver = 'xxx@qq.com'
subject = 'XX通知'
smtpserver = 'smtp.163.com'
username = 'xxx@163.com'
password = 'xxx'

msg = MIMEText('大家好','plain','utf-8')#中文需参数‘utf-8',单字节字符不需要
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = 'xxx<xxx@163.com>'
msg['To'] = "xxx@qq.com"
smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()