import smtplib
from email.mime.text import MIMEText
from email.header import Header
def email(title):
sender = '14@qq.com'#填写发件人
pwd = 'ioeot'#登录密码
receivers = ['877qq.com']#填写收件人
message = MIMEText(f"你好,网站有内容更新{title},请及时查看http://ss.scnu.edu.cn/yanjiushengjiaoxue/yanjiushengzhaosheng/","plain",'utf-8')
# 三个参数:第一个为文本内容,第二个为plain设置文本格式,第三个为utf-8设置编码
message ['From'] = "lhq <1481@qq.com>"
message ['To'] = "李华 <8771
qq.com>"
subject = "网站有内容更新"
#邮件主题
message["Subject"] = subject
try:
# 使用非本地服务器,需要建立ssl连接
smtpObj = smtplib.SMTP_SSL("smtp.qq.com",465)
print("邮件发送成功")
#发件箱邮件服务器
smtpObj.login(sender,pwd)
smtpObj.sendmail(sender,receivers,message.as_string())
print("邮件发送成功")
except smtplib.SMTPException as e:
print("Error:无法发送邮件.Case:%s"%e)