#!/usr/bin/python
# ——*—— coding=utf-8 __*__
#author: zhangdonghong
#email: zhangdonghongemail@163.com
#date: 2014-11-17
import smtplib
from email.Header import Header
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
def sent_mail(rcpt):
sender = "service@only.cn"
msg = MIMEMultipart(‘alternative‘)
msg[‘Subject‘] = Header("(AD)定情之吻,让TA为你倾情","utf-8")
msg[‘From‘] = "%s <service@only.cn>" % Header("Only","utf-8")
msg[‘To‘] = rcpt
#only.html is the AD page
html = open(‘only.html‘).read()
html_part = MIMEText(html,‘html‘)
html_part.set_charset(‘utf-8‘)
msg.attach(html_part)
try:
s = smtplib.SMTP()
s.connect(‘127.0.0.1:25‘)
s.login(‘zhangdonghong‘,‘zdh@#123:)‘)
s.sendmail(sender,rcpt,msg.as_string())
s.quit()
print ‘%s 邮件发送成功‘ % rcpt
except Exception,e:
print e
print ‘%s 邮件发送失败‘ % rcpt
if __name__ == ‘__main__‘:
#save all email address with list.txt
for line in open("list.txt"):
#print line,
sent_mail(line)
本文出自 “zhangdh开放空间” 博客,请务必保留此出处http://linuxblind.blog.51cto.com/7616603/1711940
原文地址:http://linuxblind.blog.51cto.com/7616603/1711940