2024-08-17 11:25:51 +08:00
|
|
|
from email.mime.text import MIMEText
|
|
|
|
from email.utils import parseaddr, formataddr
|
|
|
|
from email.header import Header
|
|
|
|
import aiosmtplib
|
|
|
|
from .cfg import config
|
|
|
|
|
|
|
|
|
|
|
|
SMTP_SRV = config["email"]["smtp_srv"]
|
|
|
|
PORT = config["email"]["port"]
|
|
|
|
ADDR = config["email"]["addr"]
|
|
|
|
PASSWD = config["email"]["passwd"]
|
|
|
|
|
|
|
|
|
|
|
|
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
|