This repository was archived by the owner on Dec 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsend_logs.py
More file actions
53 lines (42 loc) · 1.64 KB
/
send_logs.py
File metadata and controls
53 lines (42 loc) · 1.64 KB
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
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
"""
"""
# @Time: 2017/6/25 10:28
# @Author:still_night@163.com
# @File: send_logs.py
import const
import sys
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
import send_mail
import os
def send_log():
sender = const.SMTPFULLADDRESS
receivers = ['531903884@qq.com'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
# 创建一个带附件的实例
message = MIMEMultipart()
message['From'] = Header("一键评教", 'utf-8')
message['To'] = Header("程序猿", 'utf-8')
subject = '[一键评教]日志'
message['Subject'] = Header(subject, 'utf-8')
# 邮件正文内容
message.attach(MIMEText('日志', 'plain', 'utf-8'))
for each in ("jwpj_info.log","jwpj.log","jwpj_err.log"):
if os.path.exists(each):
# 构造附件1,传送当前目录下的 test.txt 文件
att = MIMEText(open('/root/yjpj/%s'%each, 'rb').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
# 这里的filename可以任意写,写什么名字,邮件中显示什么名字
att["Content-Disposition"] = 'attachment; filename="%s.txt"'%each
message.attach(att)
try:
smtpObj = send_mail.login()
smtpObj.sendmail(sender, receivers, message.as_string())
print "邮件发送成功"
except smtplib.SMTPException:
print "Error: 无法发送邮件"
if __name__ == '__main__':
if not sys.platform == "win32":
send_log()