首页 > 编程语言 > 详细

用Python发送html类型的广告邮件

时间:2015-11-11 22:17:27      阅读:488      评论:0      收藏:0      [点我收藏+]

#!/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

用Python发送html类型的广告邮件

原文:http://linuxblind.blog.51cto.com/7616603/1711940

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!