1 if __name__ == '__main__':
2 ToUser='zhoujiebing@maimiaotech.com'
3 filestr = 'html'
4 html = file(filestr).read()
5 sendEmail(ToUser, (filestr, html), u'主题')
1 import sys
2 import smtplib
3 from email.mime.text import MIMEText
4 from email.mime.multipart import MIMEMultipart
5
6 def sendEmail(msgTo, content, type):
7 (attachment,html) = content
8 msg = MIMEMultipart()
9 msg['Subject'] = type
10 msg['From'] = 'zhoujiebing@maimiaotech.com'
11 msg['To'] = msgTo
12 html_att = MIMEText(html, 'html', 'utf-8')
13 att = MIMEText(attachment, 'plain', 'utf-8')
14 msg.attach(html_att)
15 msg.attach(att)
16 try:
17 smtp = smtplib.SMTP()
18 smtp.connect('smtp.**.163.com', 25)
19 smtp.login(msg['From'], '自己邮箱密码')
20 smtp.sendmail(msg['From'], msg['To'].split(','), msg.as_string())
21 except Exception,e:
22 print e