其他一切正常,只有发邮件这一部分运行出错
def email():
mail_host = "smtp.qq.com"
mail_user = "xxx@qq.com"
mail_pass = "xxx"
sender = 'xxx@qq.com'
receivers = ['xxxx@qq.com']
message = MIMEText('今日健康打卡已成功', 'plain', 'utf-8')
message['From'] = Header("pyy", 'utf-8')
message['To'] = Header("测试", 'utf-8')
subject = '自动 SMTP 打卡'
message['Subject'] = Header(subject, 'utf-8')
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print("邮件发送成功")
except smtplib.SMTPException:
print("Error: 无法发送邮件")
错误如下
pycharm中