import smtplib
from email.mime.text import MIMEText
import requests
sender = ‘xxx’ #发送人邮箱
passwd = ‘xxxx’ #发送人邮箱授权码
receivers = ‘xxxx’ #收件人邮箱
subject = ‘python发邮件测试’ #主题
content = ‘这是我使用python smtplib模块和email模块自动发送的邮件’ #正文
msg = MIMEText(content,‘plain’,‘utf-8’)
msg[‘Subject’] = subject
msg[‘From’] = sender
msg[‘TO’] = receivers
try:
s = smtplib.SMTP_SSL(‘smtp.163.com’,465)
s.login(sender,passwd)
s.sendmail(sender,receivers,msg.as_string())
print(‘发送成功’)
except Exception:
print(‘发送失败’)