zoukankan      html  css  js  c++  java
  • python auto send email

    /***************************************************************************
     *                     python auto send email 
     * 声明:
     *     本文主要是记录如何使用python的smtplib发邮件,中间遇到授权密码和邮箱
     * 密码不同的问题。
     *
     *                                          2016-2-17 深圳 南山平山村 曾剑锋
     **************************************************************************/
    
    一、参考文章:
        163邮箱报错WARN: 535 Error: authentication failed.啥问题?
            http://www.zhihu.com/question/32009096
    
    二、error:
        1. 错误现象:
            (535, 'Error: authentication failed')
        2. 解决办法:
            smtplib用的邮箱登入密码是授权密码,不是邮箱密码。授权密码需要在邮箱设置中设置,我用的是163的邮箱,所以需要在163邮箱中设置。
    
    三、demo code:
        # encoding: utf-8
        import smtplib
        
        sender = "zengjf42@163.com"
        receivers = ["64128306@qq.com"]
        
        message = """From: zengjf <zengjf42@163.com>
        To: zoro <64128306@qq.com>
        Subject: test email for python
        
        this is a test email.
        """
        
        try:
            smtpObj = smtplib.SMTP()
            smtpObj.connect("smtp.163.com", "25") 
            # 千万请注意下面的password是授权密码,不是邮箱的密码。
            # 授权密码需要在163邮箱设置中设置。
            state = smtpObj.login("zengjf42@163.com", "填入授权密码")
            if state[0] == 235:
                smtpObj.sendmail(sender, receivers, message)
                print "send email success"
            smtpObj.quit()
        except smtplib.SMTPException, e:
            print str(e)
            
  • 相关阅读:
    ContactManager示例解析
    CubeLiveWallpaper例子解析
    BluetoothChat例子解析
    推荐一个模板引擎 templateengine
    jQuery plugin: Autocomplete
    乐从网站建设、域名、主机-www.lecong.me-www.lecong.mobi
    C#操作注册表
    .NET模板引擎
    [转]模版引擎AderTemplate源代码分析笔记
    windows服务器文件同步,网站同步镜像
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/5195700.html
Copyright © 2011-2022 走看看