可以参考菜鸟教程:http://www.runoob.com/python3/python3-smtp.html
import smtplib import email.mime.multipart import email.mime.text msg=email.mime.multipart.MIMEMultipart() msg['from']='[email protected]' msg['to']='[email protected]' msg['subject']='给你的一封信' content="你好" txt=email.mime.text.MIMEText(content) msg.attach(txt) smtp=smtplib.SMTP() smtp.connect('smtp.163.com') smtp.login('[email protected]',password) smtp.sendmail('[email protected]','[email protected]',str(msg))