Try to write a script to send e-mail but failed

#-*-coding: utf-8 -*-

'''
使用Python去发送邮件
但是不成功,运行后,等待一段时间, 返回[Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
email send fail
'''

import smtplib
from email.mime.text import MIMEText


HOST='smtp.163.com'
PORT=25
TIMEOUT='30'
USER='m17606719860'
USERA='m17606719860@163.com'
PREFIX='163.com'
PASSWORD='cc1842'
to_list=['chen.chen@ecitele.com']
content='python send email test'
sub='hello,world'


def sendmail(to_list,sub,content):
me='hello'+'<'+USER+'@'+PREFIX+'>'
msg=MIMEText(content,_subtype='plain',_charset='gb2312')
msg['Subject']= sub
msg['From']=me
msg['To']=','.join(to_list)
try:
smtp=smtplib.SMTP()
smtp.set_debuglevel(1)
smtp.connect(HOST,PORT)
smtp.login(USER,PASSWORD)
smtp.sendmail(me,to_list,msg.as_string())
smtp.quit()
print 'email send success'
except Exception,e:
print e
print 'email send fail'


if __name__=='__main__':sendmail(to_list,sub,content)

 

posted @ 2016-10-29 09:53  yushangcc  阅读(242)  评论(0编辑  收藏  举报