Try to write a script to send e-mail but failed
Posted yushangcc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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=‘[email protected]‘
PREFIX=‘163.com‘
PASSWORD=‘cc1842‘
to_list=[‘[email protected]‘]
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的主要内容,如果未能解决你的问题,请参考以下文章
Writing Your First Script And Getting It To Work
3 Ways to Write Text to a File in Python