码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-11-11 22:18:43      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:mail postfix python html

#!/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类型的广告邮件

标签:mail postfix python html

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!