sacn_accout_system/server/email.py

31 lines
793 B
Python

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>]"
if (SMTP_SRV == ''):
return 0
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