Repository navigation
Expand file tree
/
Copy pathmail.py
More file actions
49 lines (44 loc) · 1.36 KB
/
Copy pathmail.py
File metadata and controls
49 lines (44 loc) · 1.36 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
#!/usr/bin/env python
# -*- coding: gbk -*-
from __future__ import unicode_literals
import smtplib
from email.mime.text import MIMEText
class Mail():
"""
发送邮件
"""
#设置服务器,用户名、口令以及邮箱的后缀
mail_host = "smtp.163.com"
mail_user = "autorunforscott@163.com"
mail_pass = "autorun"
mail_postfix = "163.com"
def SendMail(self,fromWho, toList, title, content, fromAddress=None):
'''
toList:发给谁
fromAddtress:来自于
title:主题
content:内容
Mail().SendMail(["qianlf2008@163.com,test@test.com"], "title", "content"):
'''
me = "%s<autorunforscott@163.com>" % fromWho
if fromAddress is None:
fromAddress = me
msg = MIMEText(content)
msg['Subject'] = title
msg['From'] = fromAddress
msg['To'] = ";".join(toList)
try:
s = smtplib.SMTP()
s.connect(self.mail_host)
s.login(self.mail_user, self.mail_pass)
s.sendmail(me, toList, msg.as_string())
s.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == "__main__":
if Mail().SendMail('qianlifeng',["qianlf2008@163.com"], "title", "content"):
print "发送成功"
else:
print "发送失败"