refactor: 移除邮件功能
发信能力整体下线,唯一的调用方(忘记密码)前端也从来没接过。 - utils/shortcuts.py 删 send_email,连带四个 django.core.mail 相关 import - account/tasks.py 整个删除,里面只有 send_email_async 一个 actor - 删 ApplyResetPasswordAPI / ResetPasswordAPI 及其路由、serializer, User.reset_password_token 和 reset_password_token_expire_time 两个 字段(account/0010) - 删 SMTPAPI / SMTPTestAPI 及其路由、三个 SMTP serializer、 SysOptions.smtp_config - account/templates/reset_password_email.html options/0003 数据迁移删掉库里的 smtp_config 行:_init_option 会为每个 OptionKey 建行,key 从代码里去掉后它会变成孤儿,而且配过 SMTP 的话 value 里存着明文密码。 保留 ResetUserPasswordAPI(管理端直接重置密码,不发信,前端在用)和 User.email(注册要填)。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,12 +2,9 @@ import os
|
||||
import random
|
||||
import re
|
||||
from base64 import b64encode
|
||||
from email.utils import formataddr
|
||||
from io import BytesIO
|
||||
|
||||
from django.core.mail import EmailMultiAlternatives, get_connection
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.html import strip_tags
|
||||
|
||||
|
||||
def rand_str(length=32, type="lower_hex"):
|
||||
@@ -63,25 +60,6 @@ def natural_sort_key(s, _nsre=re.compile(r"(\d+)")):
|
||||
return [int(text) if text.isdigit() else text.lower() for text in re.split(_nsre, s)]
|
||||
|
||||
|
||||
def send_email(smtp_config, from_name, to_email, to_name, subject, content):
|
||||
connection = get_connection(
|
||||
host=smtp_config["server"],
|
||||
port=smtp_config["port"],
|
||||
username=smtp_config["email"],
|
||||
password=smtp_config["password"],
|
||||
use_tls=smtp_config["tls"],
|
||||
)
|
||||
message = EmailMultiAlternatives(
|
||||
subject=subject,
|
||||
body=strip_tags(content),
|
||||
from_email=formataddr((from_name, smtp_config["email"])),
|
||||
to=[formataddr((to_name, to_email))],
|
||||
connection=connection,
|
||||
)
|
||||
message.attach_alternative(content, "text/html")
|
||||
return message.send()
|
||||
|
||||
|
||||
def get_env(name, default=""):
|
||||
return os.environ.get(name, default)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user