码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-10-29 11:51:49      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:成功   fail   ref   com   rom   plain   debug   use   from   

#-*-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)

 

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

标签:成功   fail   ref   com   rom   plain   debug   use   from   

原文地址:http://www.cnblogs.com/AlwaysT-Mac/p/6010103.html

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