Skip to content

Commit b174fb6

Browse files
committed
python-mail
1 parent 7b1d27c commit b174fb6

File tree

4 files changed

+116
-3
lines changed

4 files changed

+116
-3
lines changed

flask_monitor/web/templates/mon.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
66
<title>Highstock Example</title>
77

8-
<script type="text/javascript" src="{{ url_for('static', filename='jquery.min.js') }}"></script>
8+
<!-- <script type="text/javascript" src="{{ url_for('static', filename='jquery.min.js') }}"></script> -->
9+
<script type="text/javascript" src="http://ajax.useso.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
910
<style type="text/css">
1011
${demo.css}
1112
</style>
@@ -39,8 +40,10 @@
3940
</script>
4041
</head>
4142
<body>
42-
<script src="{{ url_for('static', filename='highstock.js') }}"></script>
43-
<script src="{{ url_for('static', filename='exporting.js') }}"></script>
43+
<!-- <script src="{{ url_for('static', filename='highstock.js') }}"></script> -->
44+
<script src="http://cdnjs.cloudflare.com/ajax/libs/highstock/2.0.4/highstock.js"></script>
45+
<!-- <script src="{{ url_for('static', filename='exporting.js') }}"></script> -->
46+
<script src="http://code.highcharts.com/modules/exporting.js"></script>
4447

4548

4649
<div id="container" style="height: 400px"></div>

mail/linux/mail.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
#-*- encoding: utf-8 -*-
3+
#
4+
5+
6+
import smtplib
7+
from email.mime.text import MIMEText
8+
from email.header import Header
9+
10+
def send_email(title = '软件监控通知邮件',meial_server = '',from_name = '', from_pwd = '' ,to_name_list=[],message=''):
11+
msg = MIMEText(message,'html',_charset='UTF-8') #设置UTF-8编码
12+
msg['Subject'] =Header(title,"UTF-8") #设置UTF-8编码
13+
msg['From'] = meial_server
14+
msg['To'] = ";".join(to_name_list)
15+
#print msg
16+
try:
17+
s = smtplib.SMTP()
18+
s.connect(meial_server)
19+
s.login(from_name,from_pwd)
20+
s.sendmail(from_name, to_name_list, msg.as_string())
21+
return True
22+
except Exception, e:
23+
print str(e)
24+
return False
25+
finally:
26+
s.close()
27+
28+
29+
if __name__=="__main__":
30+
print send_email(title='软件监控通知邮件',meial_server='smtp.163.com',from_name='[email protected]',from_pwd='password',to_name_list=['[email protected]','[email protected]'],message='恭喜您,邮件发送成功!')

mail/linux/mail2.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# coding:utf-8
2+
import smtplib
3+
from email.mime.text import MIMEText
4+
from email.header import Header
5+
import time
6+
import os
7+
import sys
8+
9+
def send_mail(subject, body, mail_to, username, password, mail_type='plain'):
10+
assert isinstance(mail_to, list) == True
11+
msg = MIMEText(body,'html',_charset='UTF-8')
12+
# 定义标题
13+
msg['Subject'] = Header(subject,"UTF-8")
14+
# 定义发信人
15+
msg['From'] = username
16+
#
17+
msg['To'] = ';'.join(mail_to)
18+
# 定义发送时间(不定义的可能有的邮件客户端会不显示发送时间)
19+
msg['date'] = time.strftime('%a, %d %b %Y %H:%M:%S %z')
20+
try:
21+
smtp = smtplib.SMTP()
22+
# 连接SMTP服务器,
23+
smtp.connect('smtp.163.com')
24+
# 用户名密码
25+
smtp.login(username, password)
26+
smtp.sendmail(username, mail_to, msg.as_string())
27+
smtp.quit()
28+
return True
29+
except Exception as e:
30+
print "send mail error:%s"%e
31+
return False
32+
33+
if __name__ == "__main__":
34+
35+
if len(sys.argv) < 2:
36+
print 'Usage : python mail.py object_mail'
37+
sys.exit()
38+
39+
subject = '你好,这是一封测试邮件'
40+
body = '''
41+
这是经过我们的python程序发送的一封邮件,请勿直接回复
42+
'''
43+
mail_to = [sys.argv[1]]
44+
username = '[email protected]'
45+
#password = os.getenv('PASSWORD')
46+
password = 'password'
47+
send_mail(subject, body, mail_to, username, password)

mail/windows/mail.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: cp936 -*-
2+
import smtplib
3+
from email.mime.text import MIMEText
4+
from email.header import Header
5+
6+
7+
mail_host="smtp.163.com" #设置服务器
8+
mail_user="itybku" #用户名
9+
mail_pass="password" #口令
10+
mail_postfix="163.com" #发件箱的后缀
11+
12+
def send_mail(to_list,sub,content):
13+
me="[email protected]"+"<"+mail_user+"@"+mail_postfix+">"
14+
msg = MIMEText(content,'plain',_charset='gb2312')
15+
msg['Subject'] = Header(sub,"gb2312")
16+
msg['From'] = me
17+
msg['To'] = ";".join(to_list)
18+
try:
19+
server = smtplib.SMTP()
20+
server.connect(mail_host)
21+
server.login(mail_user,mail_pass)
22+
server.sendmail(me, to_list, msg.as_string())
23+
server.close()
24+
return True
25+
except Exception, e:
26+
print str(e)
27+
return False
28+
if __name__ == '__main__':
29+
if send_mail(mailto_list,"标题!","正常文!"):
30+
print "发送成功"
31+
else:
32+
print "发送失败"
33+

0 commit comments

Comments
 (0)