#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 固定配置的邮件发送脚本 """ import smtplib import ssl from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 简化版 - 监控MySQL配置值变化 """ import time import pymysql import datetime # 数据库配置 DB_CONFIG = { 'host': '127.0.0.1', 'port': 3306, 'user': 'root', 'password': 'Blossom2$', 'database': 'usdt_mall', 'charset': 'utf8mb4' } # 监控配置 CHECK_INTERVAL = 600 # 10分钟 CONFIG_KEY = 'receiving_address' def get_value(): """获取当前值""" try: conn = pymysql.connect(**DB_CONFIG) with conn.cursor() as cursor: cursor.execute( "SELECT config_value FROM system_config WHERE config_key = %s", (CONFIG_KEY,) ) result = cursor.fetchone() return result[0] if result else None except Exception as e: print(f"查询出错: {e}") return None finally: if 'conn' in locals(): conn.close() def send_email(subject, body): """发送固定内容的邮件""" # ===== 配置信息 ===== # SMTP服务器配置 smtp_server = "smtppro.zoho.com" port = 465 # SSL端口 # 发件人信息(请修改为你的密码) sender_email = "info@as1688.vip" sender_password = "jexSRAGgpmy0" # 收件人列表 receivers = [ "Williamjohson9699@gmail.com", "info@as1688.vip" ] # =================== # 创建邮件 message = MIMEMultipart() message["From"] = sender_email message["To"] = ", ".join(receivers) # 多个收件人用逗号分隔 message["Subject"] = subject # 添加邮件正文 message.attach(MIMEText(body, "plain", "utf-8")) try: # 创建SSL连接 context = ssl.create_default_context() print(f"正在连接到 {smtp_server}...") print(f"发件人: {sender_email}") print(f"收件人: {', '.join(receivers)}") print(f"主题: {subject}") print(f"内容: {body}") # 连接到SMTP服务器 with smtplib.SMTP_SSL(smtp_server, port, context=context) as server: # 登录 print("正在登录...") server.login(sender_email, sender_password) # 发送邮件 print("正在发送邮件...") server.send_message(message) print("✅ 邮件发送成功!") except Exception as e: print(f"❌ 发送邮件时出错: {e}") print("\n可能的原因:") print("1. 密码错误 - 请检查 sender_password 是否正确") print("2. 需要应用专用密码 - 请在Zoho邮箱生成应用专用密码") print("3. 网络连接问题 - 请检查网络连接") print("4. SMTP设置问题 - 确认Zoho邮箱已开启SMTP访问") if __name__ == "__main__": print(f"开始监控 {CONFIG_KEY} 的变化...") print(f"检查间隔: {CHECK_INTERVAL/60} 分钟") print("-" * 50) previous = get_value() print(f"初始值: {previous}") count = 0 while True: time.sleep(CHECK_INTERVAL) count += 1 current = get_value() if current is None: continue if current != previous: print(f"[{datetime.datetime.now()}] 值发生变化!") print(f" 旧值: {previous}") print(f" 新值: {current}") previous = current send_email(f"[{datetime.datetime.now()}] 值发生变化!", f" 旧值: {previous} 新值: {current}") else: print(f"[{datetime.datetime.now()}] 第{count}次检查: 值未变化")