sacn_accout_system/server/email.py

38 lines
872 B
Python
Raw Permalink Normal View History

2024-08-17 11:25:51 +08:00
from email.mime.text import MIMEText
from email.header import Header
import aiosmtplib
2024-08-25 20:51:14 +08:00
from . import cfg
2024-08-17 11:25:51 +08:00
2024-08-25 20:51:14 +08:00
def load_cfg():
global SMTP_SRV
global PORT
global ADDR
global PASSWD
SMTP_SRV = cfg.config["email"]["smtp_srv"]
PORT = cfg.config["email"]["port"]
ADDR = cfg.config["email"]["addr"]
PASSWD = cfg.config["email"]["passwd"]
load_cfg()
2024-08-17 11:25:51 +08:00
async def sendemail(to_addr, links):
print(links)
html = "验证链接:[<a href=\""+links+"\">"+links+"</a>]"
2024-08-25 20:05:24 +08:00
if (SMTP_SRV == ''):
return 0
2024-08-17 11:25:51 +08:00
msg = MIMEText(html, 'html', 'utf-8')
msg['From'] = ADDR
msg['To'] = to_addr
msg['Subject'] = Header('StudyAreaCN 帐号', 'utf-8').encode()
async with aiosmtplib.SMTP(hostname=SMTP_SRV, port=PORT, use_tls=True) as smtp:
await smtp.login(ADDR, PASSWD)
await smtp.send_message(msg)
return 0