zoukankan      html  css  js  c++  java
  • Python发送邮件不需要发件人密码认证

    #!/usr/bin/python
    
    # coding: UTF-8
     
    import smtplib
    from email.mime.text import MIMEText
     
     
    receivers_list=["chengang@example.com",]
    #mail_host="dns.com"
    mail_host="1.2.3.4"
    sender_email="send@bat.com"
    #mail_pwd="*************" //有的需要,有的不需要
      
      
    def send_email(subject, content, receivers_list):
        print 'Setting MIMEText'
        msg = MIMEText(content.encode('utf8'), _subtype = 'html', _charset = 'utf8')
        msg['From'] = sender_email
        msg['Subject'] = u'%s' % subject
        msg['To'] = ",".join(receivers_list)
     
        try:
            # s = smtplib.SMTP_SSL(mail_host, 465) //有的需要,有的不需要
            s = smtplib.SMTP(mail_host, 25)
            # s.connect(mail_host) //和上面的连接任选一种
            #s.set_debuglevel(1)
            #s.ehlo() //有的需要,有的不需要
            #s.starttls() //有的需要,有的不需要
            #s.ehlo()
            #s.login(mail_user, mail_pwd) //有的需要,有的不需要
     
            s.sendmail(sender_email, receivers_list, msg.as_string())
     
            print 'close the connection between the mail server'
            s.close()
        except Exception as e:
            print 'Exception: ', e
     
    if __name__ == '__main__':
        send_email("subject title", 'email content', receivers_list)
    

      

  • 相关阅读:
    Tomcat原理与实践
    Spring Boot入门与实践
    Docker安装及使用
    JDK源码解析——集合(一)数组 ArrayList
    浅谈mysql底层索引
    微信小程序全局配置知识点
    uniapp全屏高度
    npm node-sass报错
    微信小程序接口配置问题
    微信小程序的设计流程
  • 原文地址:https://www.cnblogs.com/linkxu1989/p/9998932.html
Copyright © 2011-2022 走看看