Skip to content

Commit b73aed9

Browse files
committed
添加邮件发送功能
1 parent c8c7474 commit b73aed9

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding//Notification/mail.py=gbk

Notification/mail.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,51 @@
1-
'''
2-
Created on 2012-9-7
1+
#!/usr/bin/env python
2+
# -*- coding: gbk -*-
3+
from __future__ import unicode_literals
4+
import smtplib
5+
from email.mime.text import MIMEText
36

4-
@author: lifqian
5-
'''
7+
class Mail():
8+
"""
9+
发送邮件
10+
"""
11+
12+
#设置服务器,用户名、口令以及邮箱的后缀
13+
mail_host = "smtp.163.com"
14+
mail_user = "[email protected]"
15+
mail_pass = "autorun"
16+
mail_postfix = "163.com"
17+
18+
def SendMail(self, toList, title, content,fromAddress=None):
19+
'''
20+
toList:发给谁
21+
fromAddtress:来自于
22+
title:主题
23+
content:内容
24+
send_mail("[email protected]","sub","content")
25+
'''
26+
me = "AutorunForScott<[email protected]>"
27+
if fromAddress is None:
28+
fromAddress = me
29+
30+
msg = MIMEText(content)
31+
msg['Subject'] = title
32+
msg['From'] = fromAddress
33+
msg['To'] = ";".join(toList)
34+
try:
35+
s = smtplib.SMTP()
36+
s.connect(self.mail_host)
37+
s.login(self.mail_user, self.mail_pass)
38+
s.sendmail(me, toList, msg.as_string())
39+
s.close()
40+
return True
41+
except Exception, e:
42+
print str(e)
43+
return False
44+
645

7-
test
46+
47+
if __name__ == "__main__":
48+
if Mail().SendMail("[email protected]", "title", "content"):
49+
print "发送成功"
50+
else:
51+
print "发送失败"

0 commit comments

Comments
 (0)