import smtplib from email.mime.text import MIMEText mailserver = "smtp.163.com" #邮箱服务器地址 username_send = 'aaa@163.com' #邮箱用户名 password = '*' #邮箱密码:需要使用授权码 username_recv = 'aaa@qq.com' #收件人,多个收件人用逗号隔开 mail = MIMEText('邮件内容') mail['Subject'] = '邮件主题' mail['From'] = username_send #发件人 mail['To'] = username_recv #收件人; smtp = smtplib.SMTP(mailserver,port=25) # 普通邮件 # smtp=smtplib.SMTP_SSL('smtp.qq.com',port=465) #加密邮件 smtp.login(username_send,password) #登录邮箱 smtp.sendmail(username_send,username_recv,mail.as_string())# 参数分别是发送者,接收者,第三个是把上面的发送邮件的内容变成字符串 smtp.quit() # 发送完毕后退出smtp print ('发送成功')
来源:https://www.cnblogs.com/changjiangwei/p/12210827.html