-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMailUtil.py
32 lines (29 loc) · 832 Bytes
/
MailUtil.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
# coding:utf-8
import smtplib
from email.mime.text import MIMEText
#
# send email via using smtplib
#
class MailUtil(object):
def __init__(self, to, sub, content):
self.mail_host = 'email server addr, eg: smtp.163.com'
self.mail_user = 'email address of sender'
self.mail_pass = 'your email password'
self.to = ['receiver list']
self.sub = sub
self.content = content
def sendMail(self):
msg = MIMEText(self.content, _subtype = 'plain', _charset = 'utf-8')
msg['Subject'] = self.sub
msg['From'] = self.mail_user
msg['To'] = ";".join(self.to)
try:
server = smtplib.SMTP()
server.connect(self.mail_host)
server.login(self.mail_user, self.mail_pass)
server.sendmail(self.mail_user, self.to, msg.as_string())
server.close()
return True
except Exception, e:
print str(e)
return False