Send HTML-type AD messages in Python

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.