集成邮件服务

This commit is contained in:
wcq 2023-10-08 17:00:27 +08:00
parent eefacff4ae
commit 5f3e0c31be
4 changed files with 36 additions and 6 deletions

View File

@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.9 virtualenv at D:\yuandong_work\project\wd-smebiz\venv" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">

View File

@ -1,15 +1,19 @@
from copy import deepcopy
from fastapi import APIRouter, Depends
from context.common import conf_file_path, conf, auth_util
from . import schemas
router = APIRouter(prefix="/system", dependencies=[Depends(auth_util.token_data_depend)])
router = APIRouter(
prefix="/system", dependencies=[Depends(auth_util.token_data_depend)])
@router.post("/setting/get", response_model=schemas.SettingGetRes)
def setting_get():
conf.read(conf_file_path, encoding='utf-8-sig')
return schemas.SettingGetRes(data=conf._sections)
data = deepcopy(conf._sections)
data = {k: v for k, v in data.items() if k in ['rate_utils']}
return schemas.SettingGetRes(data=data)
@router.post("/setting/update_item")

View File

@ -1,6 +1,8 @@
import asyncio
import json
import requests
import re
from fastapi_mail import FastMail, MessageSchema, ConnectionConfig, MessageType
def email_check(email: str):
@ -20,5 +22,29 @@ def send_email(title: str, email: str, msg_body: str, email_api="http://email_ap
"recipients": [email],
"msg_body": msg_body,
}
res = requests.post(url=email_api + '/send_mail', headers=headers, data=json.dumps(data), timeout=5)
res = requests.post(url=email_api + '/send_mail',
headers=headers, data=json.dumps(data), timeout=5)
return res.status_code == 200
conf = ConnectionConfig(
MAIL_USERNAME="dogbillions@163.com",
MAIL_PASSWORD="RMRMGULXYJHRMATM",
MAIL_FROM="dogbillions@163.com",
MAIL_PORT=25,
MAIL_SERVER="smtp.163.com",
MAIL_FROM_NAME="维德团队",
MAIL_STARTTLS=True,
MAIL_SSL_TLS=False,
USE_CREDENTIALS=True,
VALIDATE_CERTS=True)
fm = FastMail(conf)
def send_mail(title: str, email: str, msg_body: str,sender="维德团队"):
message = MessageSchema(
subject=title,
body=f"<p>{msg_body}</p>",
subtype=MessageType.html, recipients=[email])
asyncio.run(fm.send_message(message))

View File

@ -3,7 +3,7 @@ import uuid
import requests
from enum import Enum
from captcha.image import ImageCaptcha
from utils.email_utils import send_email
from utils.email_utils import send_email,send_mail
from utils.random_utils import get_random_num_code, get_random_letter_and_num_code
from utils.redis_utils import RedisPool
@ -78,7 +78,7 @@ class EmailVerifyCode:
title = "修改信息验证码"
elif verify_type == EmailVerifyType.reset_password:
title = "修改密码验证码"
send_email(title, email, code)
send_mail(title, email, code)
def check_code(self, email, code, verify_type: EmailVerifyType = EmailVerifyType.login):
email_id = self.get_email_id(email, verify_type)