update pay ui
This commit is contained in:
53
app.py
53
app.py
@@ -3184,22 +3184,51 @@ def send_sms_code(phone, code, template_id):
|
||||
|
||||
|
||||
def send_email_code(email, code):
|
||||
"""发送邮件验证码"""
|
||||
try:
|
||||
print(f"[邮件发送] 准备发送验证码到: {email}")
|
||||
print(f"[邮件配置] 服务器: {MAIL_SERVER}, 端口: {MAIL_PORT}, SSL: {MAIL_USE_SSL}")
|
||||
"""发送邮件验证码(使用 subprocess 绕过 eventlet DNS 问题)"""
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
msg = Message(
|
||||
subject='价值前沿 - 验证码',
|
||||
recipients=[email],
|
||||
body=f'您的验证码是:{code},有效期5分钟。如非本人操作,请忽略此邮件。'
|
||||
try:
|
||||
# 获取脚本路径
|
||||
script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'email_sender.py')
|
||||
|
||||
subject = '价值前沿 - 验证码'
|
||||
body = f'您的验证码是:{code},有效期5分钟。如非本人操作,请忽略此邮件。'
|
||||
|
||||
print(f"[邮件] 准备发送验证码到 {email}")
|
||||
print(f"[邮件] 服务器: {MAIL_SERVER}:{MAIL_PORT}, SSL: {MAIL_USE_SSL}")
|
||||
|
||||
# 使用 subprocess 在独立进程中发送邮件(绕过 eventlet DNS)
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable, # 使用当前 Python 解释器
|
||||
script_path,
|
||||
email,
|
||||
subject,
|
||||
body,
|
||||
MAIL_SERVER,
|
||||
str(MAIL_PORT),
|
||||
MAIL_USERNAME,
|
||||
MAIL_PASSWORD,
|
||||
str(MAIL_USE_SSL).lower()
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=60
|
||||
)
|
||||
mail.send(msg)
|
||||
print(f"[邮件发送] 验证码邮件发送成功到: {email}")
|
||||
|
||||
if result.returncode == 0:
|
||||
print(f"[邮件] ✓ 发送成功: {result.stdout.strip()}")
|
||||
return True
|
||||
else:
|
||||
print(f"[邮件] ✗ 发送失败: {result.stderr.strip()}")
|
||||
return False
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
print(f"[邮件] ✗ 发送超时")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"[邮件发送错误] 发送到 {email} 失败: {str(e)}")
|
||||
print(f"[邮件发送错误] 错误类型: {type(e).__name__}")
|
||||
print(f"[邮件] ✗ 发送异常: {type(e).__name__}: {e}")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
64
email_sender.py
Normal file
64
email_sender.py
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
独立的邮件发送脚本(绕过 eventlet DNS 问题)
|
||||
|
||||
使用方式:
|
||||
python email_sender.py <to_email> <subject> <body> <smtp_server> <smtp_port> <username> <password> <use_ssl>
|
||||
|
||||
返回值:
|
||||
成功返回 0,失败返回 1
|
||||
"""
|
||||
|
||||
import sys
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
|
||||
|
||||
def send_email(to_email, subject, body, smtp_server, smtp_port, username, password, use_ssl):
|
||||
"""发送邮件"""
|
||||
try:
|
||||
# 创建邮件
|
||||
msg = MIMEMultipart()
|
||||
msg['From'] = username
|
||||
msg['To'] = to_email
|
||||
msg['Subject'] = subject
|
||||
msg.attach(MIMEText(body, 'plain', 'utf-8'))
|
||||
|
||||
# 连接 SMTP 服务器
|
||||
if use_ssl:
|
||||
server = smtplib.SMTP_SSL(smtp_server, smtp_port, timeout=30)
|
||||
else:
|
||||
server = smtplib.SMTP(smtp_server, smtp_port, timeout=30)
|
||||
server.starttls()
|
||||
|
||||
# 登录并发送
|
||||
server.login(username, password)
|
||||
server.sendmail(username, [to_email], msg.as_string())
|
||||
server.quit()
|
||||
|
||||
print(f"Email sent successfully to {to_email}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"Email Error: {type(e).__name__}: {e}")
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 9:
|
||||
print("Usage: python email_sender.py <to_email> <subject> <body> <smtp_server> <smtp_port> <username> <password> <use_ssl>")
|
||||
sys.exit(1)
|
||||
|
||||
to_email = sys.argv[1]
|
||||
subject = sys.argv[2]
|
||||
body = sys.argv[3]
|
||||
smtp_server = sys.argv[4]
|
||||
smtp_port = int(sys.argv[5])
|
||||
username = sys.argv[6]
|
||||
password = sys.argv[7]
|
||||
use_ssl = sys.argv[8].lower() == 'true'
|
||||
|
||||
success = send_email(to_email, subject, body, smtp_server, smtp_port, username, password, use_ssl)
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user