-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_mail.py
28 lines (22 loc) · 761 Bytes
/
send_mail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from smtplib import SMTP
from email.message import EmailMessage
import json
# 获取必要数据
with open("./account.json", "r", encoding='utf-8') as f:
account = json.load(f)
with open("./info.json", "r", encoding='utf-8') as f:
info = json.load(f)
# 构造邮件
msg = EmailMessage()
msg["Subject"] = f'TFTS播客字幕: {info["title"]}'
msg["From"] = account["address"]
msg["To"] = "[email protected]"
msg.set_content(info["summary"])
with open("subscript.pdf", "rb") as f:
msg.add_attachment(f.read(), maintype="application", subtype="pdf", filename="subscript.pdf")
# 发送邮件
server = SMTP(host="smtp.126.com", port='25')
server.login(account["address"], account["password"])
server.send_message(msg)
print("发送成功!")
server.quit()