-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendEmail.py
32 lines (32 loc) · 999 Bytes
/
sendEmail.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
29
30
31
32
import smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
import os
import yaml
def sendEmail(sender,receiver,content,filePath):
config = {}
base_path = os.path.dirname(os.path.abspath(__file__))
with open(base_path + "/config.yaml") as f:
config = yaml.load(f, Loader=yaml.BaseLoader)
sender_email = sender
receiver_email = receiver
password = 'exevqmxmkrcthcbg'
content = content
textApart = MIMEText(content)
pdfFile = filePath
fileName = '153'
pdfApart = MIMEApplication(open(pdfFile, 'rb').read())
pdfApart.add_header('Content-Disposition', 'attachment', filename=fileName)
m = MIMEMultipart()
m.attach(textApart)
m.attach(pdfApart)
m['Subject'] = 'comicPdf'
context = ssl.create_default_context()
server = smtplib.SMTP_SSL('smtp.qq.com')
server.login(sender_email, password)
server.sendmail(
sender,
receiver,
m.as_string())
server.quit()