push.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from email.mime.text import MIMEText
  2. from email.utils import formataddr
  3. import smtplib
  4. class Push(object):
  5. '''消息推送'''
  6. def __init__(self):
  7. pass
  8. def send(self, message:str):
  9. '''you must implement it and send message'''
  10. pass
  11. class SMSPush(Push):
  12. '''短信推送'''
  13. def __init__(self):
  14. pass
  15. def send(self, message:str):
  16. pass
  17. class EmailPush(Push):
  18. '''邮件推送'''
  19. def __init__(self):
  20. pass
  21. def send(self, message:str):
  22. mailserver = "smtp.yoqi.me"
  23. username = "service@yoqi.me"
  24. password = ""
  25. msg = MIMEText("域名快到期了")
  26. msg['Subject'] = "【域名到期提醒】"
  27. msg['From'] = "service@xx"
  28. msg['To'] = "xx@qq.com"
  29. try:
  30. s = smtplib.SMTP(mailserver)
  31. s.login(username, password)
  32. s.send_message(msg)
  33. s.quit()
  34. except Exception as e:
  35. print(e)
  36. class AppPush(Push):
  37. '''App推送'''
  38. def __init__(self):
  39. pass
  40. def send(self, message:str):
  41. pass
  42. if __name__ == "__main__":
  43. pass