38 lines
872 B
Python
38 lines
872 B
Python
from email.mime.text import MIMEText
|
|
from email.header import Header
|
|
import aiosmtplib
|
|
from . import cfg
|
|
|
|
|
|
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()
|
|
|
|
|
|
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
|