fix: SMTP配置更新为mail.tphai.com端口587
This commit is contained in:
@@ -374,20 +374,17 @@ def send_email():
|
|||||||
|
|
||||||
body = "\n".join(body_lines)
|
body = "\n".join(body_lines)
|
||||||
|
|
||||||
# 调用邮件发送技能
|
# 调用邮件发送
|
||||||
try:
|
try:
|
||||||
import smtplib
|
import smtplib
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
|
||||||
# SMTP配置(从环境变量或配置文件获取)
|
# SMTP配置
|
||||||
smtp_host = os.environ.get('SMTP_HOST', 'smtp.exmail.qq.com')
|
smtp_host = 'mail.tphai.com'
|
||||||
smtp_port = int(os.environ.get('SMTP_PORT', 465))
|
smtp_port = 587
|
||||||
smtp_user = os.environ.get('SMTP_USER', 'wlq@tphai.com')
|
smtp_user = 'favor@tphai.com'
|
||||||
smtp_pass = os.environ.get('SMTP_PASS', '')
|
smtp_pass = 'favor@!'
|
||||||
|
|
||||||
if not smtp_pass:
|
|
||||||
return jsonify({'success': False, 'error': 'SMTP密码未配置,请设置环境变量 SMTP_PASS'}), 500
|
|
||||||
|
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
msg['From'] = smtp_user
|
msg['From'] = smtp_user
|
||||||
@@ -396,9 +393,15 @@ def send_email():
|
|||||||
|
|
||||||
msg.attach(MIMEText(body, 'plain', 'utf-8'))
|
msg.attach(MIMEText(body, 'plain', 'utf-8'))
|
||||||
|
|
||||||
with smtplib.SMTP_SSL(smtp_host, smtp_port) as server:
|
# 端口587无SSL,尝试STARTTLS,失败则用普通连接
|
||||||
|
server = smtplib.SMTP(smtp_host, smtp_port)
|
||||||
|
try:
|
||||||
|
server.starttls()
|
||||||
|
except smtplib.SMTPNotSupportedError:
|
||||||
|
pass # 服务器不支持TLS,继续用普通连接
|
||||||
server.login(smtp_user, smtp_pass)
|
server.login(smtp_user, smtp_pass)
|
||||||
server.sendmail(smtp_user, email_addr, msg.as_string())
|
server.sendmail(smtp_user, email_addr, msg.as_string())
|
||||||
|
server.quit()
|
||||||
|
|
||||||
return jsonify({'success': True, 'message': f'已发送到 {email_addr}'})
|
return jsonify({'success': True, 'message': f'已发送到 {email_addr}'})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user