Files
chat/backend/app/services/email_service.py
T
2026-06-14 11:16:42 +08:00

27 lines
782 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""邮件服务(假实现:验证码打印到日志;以后替换为 SMTP"""
import hashlib
import secrets
def generate_code() -> str:
"""生成 6 位数字验证码"""
return f"{secrets.randbelow(1000000):06d}"
def hash_code(code: str) -> str:
return hashlib.sha256(code.encode()).hexdigest()
async def send_verification_email(to_email: str, code: str, purpose: str = "验证"):
"""发送验证邮件(开发期假实现:打印到日志)
生产环境替换此函数为真实 SMTP 发送即可,调用方无需改动。
"""
print(f"\n{'=' * 50}")
print(f"📧 [邮件服务-开发模式] 收件人: {to_email}")
print(f"📋 用途: {purpose}")
print(f"🔢 验证码: {code}")
print(f"{'=' * 50}\n")
return True