Compare commits

..

3 Commits

Author SHA1 Message Date
89b5a69325 fix: 添加邮件请求日志,便于排查发送问题 2026-06-01 17:44:39 +08:00
23810cf180 fix: 邮件发送改为 sendmail + Date头,对齐已验证脚本
- send_message() → sendmail()(与 send_email.py 一致)
- 新增 Date 头(部分SMTP服务器缺少会拦截)
- 增加发送前/后详细日志
2026-06-01 17:37:39 +08:00
16400b0359 fix: 修复邮件发送通道
- 发件账号改为 hz4th_coder@tphai.com(替换无效的 favor@tphai.com)
- 发件人名称: 黄庄4号程序员
- 连接前添加 server.ehlo() 调用(对齐 send_email.py 工作脚本)
- 无SSL/无STARTTLS 模式
2026-06-01 17:28:31 +08:00
9 changed files with 82 additions and 30340 deletions

Binary file not shown.

View File

@@ -1,9 +1,10 @@
{
"thresholds": {
"cpu": 75,
"memory": 80,
"disk": 85,
"interval": 60
"interval": 60,
"memory": 80,
"cpu_temp": 70
},
"web_settings": {
"external_ip": "121.40.164.32",

30388
logs/app.log

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,9 @@ def register_email_routes(app):
def api_email_send():
"""发送邮件通知"""
data = request.get_json()
log_message(f"📨 收到邮件请求: {data}")
if not data:
log_message(f"❌ 无效数据: content-type={request.content_type}")
return jsonify({'error': '无效数据'}), 400
to_email = data.get('to')
@@ -26,33 +28,40 @@ def register_email_routes(app):
body = data.get('body')
if not to_email or not subject or not body:
log_message(f"❌ 缺少参数: to={to_email}, subject={subject}, body_len={len(body) if body else 0}")
return jsonify({'error': '缺少必要参数'}), 400
try:
# SMTP配置 (从环境变量或默认值)
smtp_host = os.environ.get('SMTP_HOST', 'mail.tphai.com')
smtp_port = int(os.environ.get('SMTP_PORT', 587))
smtp_user = os.environ.get('SMTP_USER', 'favor@tphai.com')
smtp_pass = os.environ.get('SMTP_PASS', 'favor@!')
smtp_user = os.environ.get('SMTP_USER', 'hz4th_coder@tphai.com')
smtp_pass = os.environ.get('SMTP_PASS', 'hz4th_coder@!')
# 创建邮件
log_message(f"📧 准备发送邮件: to={to_email}, subject={subject}, user={smtp_user}")
# 创建邮件(完全对齐 send_email.py 的方式)
from email.utils import formataddr, formatdate
msg = MIMEMultipart()
msg['From'] = smtp_user
msg['From'] = formataddr(('黄庄4号程序员', smtp_user))
msg['To'] = to_email
msg['Subject'] = subject
msg['Date'] = formatdate(localtime=True)
# 添加正文
msg.attach(MIMEText(body, 'plain', 'utf-8'))
# 发送邮件
# 发送邮件无SSL模式完全对齐 send_email.py
server = smtplib.SMTP(smtp_host, smtp_port)
server.ehlo()
server.login(smtp_user, smtp_pass)
server.send_message(msg)
# 使用 sendmail 而非 send_message与已验证成功的脚本一致
server.sendmail(smtp_user, [to_email], msg.as_string())
server.quit()
log_message(f"邮件发送成功: {subject} -> {to_email}")
log_message(f"邮件发送成功: {subject} -> {to_email}")
return jsonify({'message': '邮件发送成功'})
except Exception as e:
log_message(f"邮件发送失败: {e}")
log_message(f"邮件发送失败: {e}")
return jsonify({'error': str(e)}), 500

View File

@@ -23,6 +23,10 @@ def get_html_template():
template_content = template_content.replace('v3.4.0', APP_VERSION)
template_content = template_content.replace('v3.4.1', APP_VERSION) # 预留未来版本
# 替换默认IP地址
template_content = template_content.replace("'192.168.2.17'", "'121.40.164.32'")
template_content = template_content.replace('"192.168.2.17"', '"121.40.164.32"')
return template_content
except:
# 如果文件不存在,返回基本模板