#!/usr/bin/python
#--*--coding=utf-8 __*__
#author: Zhangdonghong
#email: [Email protected]
#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 = "[Email protected]"
msg = Mimemultipart (' alternative ')
msg[' Subject ' = Header ("(AD) Kiss of Promise, let TA for your portrait", "Utf-8")
msg[' from ' = '%s <[email protected]> '% 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 ', ' [email protected] #123:) ')
S.sendmail (sender,rcpt,msg.as_string ())
S.quit ()
print '%s mail sent successfully '% RCPT
Except Exception,e:
Print E
print '%s mail failed '% RCPT
if __name__ = = ' __main__ ':
#save all email address with list.txt
For line in open ("List.txt"):
#print Line,
Sent_mail (line)
This article is from the "Zhangdh Open Space" blog, so be sure to keep this source http://linuxblind.blog.51cto.com/7616603/1711940
Send HTML-type AD messages in Python