-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleEmail.py
51 lines (42 loc) · 1.36 KB
/
ModuleEmail.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import datetime
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import platform
import Privacy
def send_email(receiver, context):
time_now = (datetime.datetime.utcnow() + datetime.timedelta(hours=8))
date_today = time_now.strftime('%Y-%m-%d')
if platform.system() == "Windows":
sender = Privacy.EmailSenderWindows
smtpserver = 'smtp.163.com'
port = 994
password = Privacy.EmailPasswordWindows
print("win")
else:
sender = Privacy.EmailSenderCentOS
smtpserver = 'smtp.gmail.com'
port = 587
password = Privacy.EmailPasswordCentOS
username = sender
subject = date_today + '贴吧签到情况'
try:
# file = open("log\\" + date_today, "r")
# msg = MIMEText(file.read(), 'plain', 'utf-8')
msg = MIMEText(context, 'plain', 'utf-8')
msg['Subject'] = Header(subject, 'gbk')
msg['From'] = sender
msg['To'] = receiver
smtp = smtplib.SMTP(smtpserver, port=port)
smtp.set_debuglevel(1)
# smtp.connect()
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
print("发送成功")
except Exception as err:
print("发送失败")
print(err)