1.發送郵件實現git
2.定時任務實現github
3.定時發送郵件實現微信
4.微信定時發送信息ui
詳細源代碼見:https://github.com/15387062910/timing_sendspa
參考:.net
廖雪峯博客 - SMTP發送郵件debug
定時任務schedule模塊code
1.發送郵件實現orm
使用smtplib
和email
兩個模塊實現郵件發送,代碼以下:server
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模塊實現定時發送:
詳情看此:http://www.javashuo.com/article/p-qonhpmqe-nb.html
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.微信定時發送信息