@@ -68,6 +68,13 @@ async def send_email(
6868 """
6969 # 动态配置
7070 dynamic_email_config = None
71+ _email_type_key = 'EMAIL'
72+ _email_status_key = 'EMAIL_STATUS'
73+ _email_host_key = 'EMAIL_HOST'
74+ _email_port_key = 'EMAIL_PORT'
75+ _email_ssl_key = 'EMAIL_SSL'
76+ _email_username_key = 'EMAIL_USERNAME'
77+ _email_password_key = 'EMAIL_PASSWORD'
7178
7279 # 检查 config 插件配置
7380 def get_config_table (conn ):
@@ -78,24 +85,24 @@ def get_config_table(conn):
7885 exists = await coon .run_sync (get_config_table )
7986
8087 if exists :
81- dynamic_email_config = await config_dao .get_by_type (db , 'email' )
88+ dynamic_email_config = await config_dao .get_all (db , _email_type_key )
8289
8390 try :
8491 # 动态配置发送
8592 if dynamic_email_config :
8693 configs = {d ['key' ]: d for d in select_list_serialize (dynamic_email_config )}
87- if configs .get ('EMAIL_STATUS' ):
94+ if configs .get (_email_status_key ):
8895 if len (dynamic_email_config ) < 6 :
8996 raise errors .NotFoundError (msg = '缺少邮件动态配置,请检查系统参数配置-邮件配置' )
9097 smtp_client = SMTP (
91- hostname = configs .get ('EMAIL_HOST' ),
92- port = configs .get ('EMAIL_PORT' ),
93- use_tls = configs .get ('EMAIL_SSL' ) == '1' ,
98+ hostname = configs .get (_email_host_key ),
99+ port = configs .get (_email_port_key ),
100+ use_tls = configs .get (_email_ssl_key ) == '1' ,
94101 )
95- message = await render_message (subject , configs .get ('EMAIL_USERNAME' ), content , template ) # type: ignore
102+ message = await render_message (subject , configs .get (_email_username_key ), content , template ) # type: ignore
96103 async with smtp_client :
97- await smtp_client .login (configs .get ('EMAIL_USERNAME' ), configs .get ('EMAIL_PASSWORD' )) # type: ignore
98- await smtp_client .sendmail (configs .get ('EMAIL_USERNAME' ), recipients , message ) # type: ignore
104+ await smtp_client .login (configs .get (_email_username_key ), configs .get (_email_password_key )) # type: ignore
105+ await smtp_client .sendmail (configs .get (_email_username_key ), recipients , message ) # type: ignore
99106
100107 # 本地配置发送
101108 message = await render_message (subject , settings .EMAIL_USERNAME , content , template )
0 commit comments