Python发送邮件
#实现邮件发送import smtplib#email实现邮件的构建from email.mime.text import MIMETextfrom email.header import Headerimport schedule,timedef job(): # 如何实现文本邮件发送 message = MIMEText(_text="正在发送邮件", _subtype=‘plain‘, _charset=‘utf-8‘) message["From"] = Header("", "utf-8") message["To"] = Header("", "utf-8") message["Subject"] = Header("python email send test", "utf-8") smtpobj = smtplib.SMTP() try: # smtp服务器地址,连接smtp服务器 mail_host = "smtp.qq.com" smtpobj.connect(host=mail_host, port="587") # 用户登录,用户名为发送者地址,密码不是账号的密码,是授权码 # 如何去获取授权码 # 发送者邮件点击设置-账户-开启pop3/smtp协议 获取授权码 user = "" smtpobj.login(user=user, password="授权码") # 实现邮件的发送 sender = "" receiver = [""] smtpobj.sendmail(sender, receiver, message.as_string()) print("邮件发送成功") except smtplib.SMTPException as e: print("邮件发送失败", e)schedule.every().day.at("21:35").do(job) # 部署在每天的10:30执行job()函数的任务# schedule.every().monday.do(job) # 部署每个星期一执行job()函数的任务# schedule.every().wednesday.at("13:15").do(job) # 部署每周三的13:15执行函数的任务# schedule.every(1).seconds.do(send_message)# schedule.every(10).minutes.do(job) # 部署每10分钟执行一次job()函数的任务# schedule.every().hour.do(job) # 部署每×小时执行一次job()函数的任务flag = Truewhile flag: schedule.run_pending() time.sleep(1)
相关推荐
zhangwentaohh 2020-09-16
文山羊 2020-08-16
行吟阁 2020-07-04
xiaodaiwang 2020-06-12
oXiaoChong 2020-06-01
sunnyhappy0 2020-05-19
airfling 2020-05-19
singer 2020-05-06
winmeanyoung 2020-04-11
wenjs00 2020-03-06
vs00ASPNET 2020-02-19
zhangpan 2020-01-10
ITxiaobaibai 2020-01-03
huakai 2019-12-29
cbao 2019-12-24
idning 2019-12-21
mrice00 2019-12-20