zoukankan      html  css  js  c++  java
  • 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)

  • 相关阅读:
    SpringSecurity开发
    SpringBoot 集成Spring Security
    Hexo
    gitbook使用
    Maze
    Party
    A. DZY Loves Chessboard
    1042B. Vitamins
    Petr and a Combination Lock
    433B.Kuriyama Mirai's Stones
  • 原文地址:https://www.cnblogs.com/AlwaysT-Mac/p/6010103.html
Copyright © 2011-2022 走看看