邮件系统配置放到yaml里面。

This commit is contained in:
liuwei
2025-05-22 11:01:14 +08:00
parent 9e07e8b5aa
commit 9f1359fbeb
3 changed files with 19 additions and 7 deletions

View File

@@ -141,3 +141,12 @@ redis_config:
db: 0
decode_responses: true
# 邮件发送配置
email_config:
smtp_server: "smtp.163.com"
smtp_port: 465
sender_email: "bovine_liu@163.com"
sender_password: "LTS9BhmX9XhS36QS"
alert_recipient: "bovine_liu@163.com" # 警报邮件接收者

View File

@@ -44,3 +44,6 @@ class Config(object):
# DB config
self.mariadb = yconfig.get("db_config", {})
self.redis = yconfig.get("redis_config", {})
# Email config
self.email = yconfig.get("email_config", {})

View File

@@ -95,10 +95,10 @@ class Robot:
# 加载插件
self.LOG.info("插件系统初始化完成")
self.email_sender = EmailSender(
smtp_server="smtp.163.com",
smtp_port=465,
sender_email="bovine_liu@163.com",
sender_password="LTS9BhmX9XhS36QS"
smtp_server=self.config.email.get("smtp_server", "smtp.163.com"),
smtp_port=self.config.email.get("smtp_port", 465),
sender_email=self.config.email.get("sender_email", "bovine_liu@163.com"),
sender_password=self.config.email.get("sender_password", "LTS9BhmX9XhS36QS")
)
def init_wechat_ipad(self):
@@ -222,7 +222,7 @@ class Robot:
self.LOG.error(f"获取新消息失败 {e}")
if "用户可能退出" in str(e):
self.LOG.error(f"用户可能退出: {e}")
self.email_sender.send_wechat_alert("bovine_liu@163.com", f"用户可能退出: {e}", self.wxid,
self.email_sender.send_wechat_alert(self.config.email.get("alert_recipient"), f"用户可能退出: {e}", self.wxid,
self.nickname)
await self.login_twice_auto_auth()
await asyncio.sleep(5)
@@ -324,7 +324,7 @@ class Robot:
self.LOG.error(f"wechat_ipad heartbeat: {e}")
if "用户可能退出" in str(e):
self.LOG.error(f"用户可能退出: {e}")
self.email_sender.send_wechat_alert("bovine_liu@163.com", f"用户可能退出: {e}", self.wxid,
self.email_sender.send_wechat_alert(self.config.email.get("alert_recipient"), f"用户可能退出: {e}", self.wxid,
self.nickname)
await self.login_twice_auto_auth()
await asyncio.sleep(60)
@@ -343,7 +343,7 @@ class Robot:
self.LOG.error(f"wechat_ipad heartbeat long: {e}")
if "用户可能退出" in str(e):
self.LOG.error(f"用户可能退出: {e}")
self.email_sender.send_wechat_alert("bovine_liu@163.com", f"用户可能退出: {e}", self.wxid,
self.email_sender.send_wechat_alert(self.config.email.get("alert_recipient"), f"用户可能退出: {e}", self.wxid,
self.nickname)
await self.login_twice_auto_auth()
await asyncio.sleep(120)