1.发送邮件实现
2.定时任务实现
3.定时发送邮件实现
4.微信定时发送信息
详细源代码见:https://github.com/15387062910/timing_send
参考:
1.发送邮件实现
使用smtplib
和email
两个模块实现邮件发送,代码如下:
1 # 发送邮件功能 2 from email import encoders 3 from email.header import Header 4 from email.mime.text import MIMEText 5 from email.utils import parseaddr, formataddr 6 from private.settings import email_info, to_addr 7 8 import smtplib 9 10 sender_user = email_info["sender_user"] 11 sender_pwd = email_info["sender_pwd"] 12 smtp_server = email_info["smtp_server"] 13 14 15 def _format_addr(s): # 格式化 16 name, addr = parseaddr(s) 17 return formataddr((Header(name, 'utf-8').encode(), addr)) 18 19 20 def send_email(content): # 发送邮件 21 msg = MIMEText(content, 'plain', 'utf-8') 22 msg['From'] = _format_addr('www.weyoung.co <%s>' % sender_user) 23 msg['To'] = _format_addr('管理员 <%s>' % to_addr) 24 msg['Subject'] = Header('LAF用户反馈', 'utf-8').encode() 25 26 server = smtplib.SMTP(smtp_server, 25) 27 server.set_debuglevel(1) 28 server.login(sender_user, sender_pwd) 29 server.sendmail(sender_user, to_addr, msg.as_string()) 30 server.quit()
2.定时任务实现
定时任务主要是使用schedule模块实现定时发送:
详情看此:https://blog.csdn.net/liao392781/article/details/80521194
3.定时发送邮件实现
1 # 实现定时功能 2 import schedule 3 from main import mail 4 from private.get import get_laf_advice # 获取数据接口 5 6 7 def send(): 8 advice = get_laf_advice() 9 mail.send_email(advice) 10 11 12 # 定时某一时刻发送邮件 13 def send_email(): 14 print("schedule") 15 schedule.every().day.at("23:48").do(send) 16 17 while True: 18 schedule.run_pending()
4.微信定时发送信息