玩蛇网提供最新Python编程技术信息以及Python资源下载!

按照《flask web开发》书中方法操作,发不出确认邮件是为什么?

import os
basedir = os.path.abspath(os.path.dirname(__file__))


class Config:
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string'
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    MAIL_SERVER = 'smtp.qq.com'
    MAIL_PORT = 25
    MAIL_USE_TLS = True
    MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
    MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
    FLASKY_MAIL_SUBJECT_PREFIX = '[Flasky]'
    FLASKY_MAIL_SENDER = 'Flasky Admin <flasky@example.com>'
    FLASKY_ADMIN = os.environ.get('FLASKY_ADMIN')

    @staticmethod
    def init_app(app):
        pass

直接从GITHUB上抄下来的,那几个邮箱值不知道该改哪几个?可能不止一处错误

报错是
raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (503, b'Error: need EHLO and AUTH first !', '=?utf-8?q?Flasky_Admin?= <flasky@example.com>')

可以参考我写的项目flask-lovehate


    MAIL_SERVER = 'smtp.qq.com'
    MAIL_PORT = 465
    MAIL_USE_SSL = True
    MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
    MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
    FLASKY_MAIL_SUBJECT_PREFIX = '[爱与生的苦恼]'
    FLASKY_MAIL_SENDER = os.environ.get('MAIL_USERNAME')

MAIL_USERNAME是邮箱,MAIL_PASSWORD是QQ Mail给的授权吗,在邮箱后台开启得到,FLASKY_MAIL_SENDER可以设为与MAIL_USERNAME一样。

换成你的qq帐号或者163邮箱帐号

具体怎么做,我忘了,你自己看看我以前写的代码吧。。。我也是闲的

# coding: utf-8
import os
from datetime import datetime
from flask.ext.moment import Moment
from flask.ext.script import Manager
from flask import Flask,render_template,session,redirect,url_for,flash
from flask.ext.bootstrap import Bootstrap
from flask.ext.wtf import Form
from wtforms import StringField,SubmitField
from wtforms.validators import Required
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.script import Shell
from flask.ext.migrate import Migrate,MigrateCommand
from flask.ext.mail import Mail
from flask.ext.mail import Message

basedir = os.path.abspath(os.path.dirname(__file__))

app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']=\
'sqlite:///'+os.path.join(basedir,'data.sqlite')
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN']=True
app.config['SECRET_KEY']='hard to guess string'
app.config['MAIL_SERVER']='smtp.qq.com'
app.config['MAIL_PORT']=465
#app.config['DEBUG']=True
app.config['MAIL_USE_TLS']=False
app.config['MAIL_USE_SSL']=True
app.config['MAIL_USERNAME']='xxxxx@qq.com'
app.config['MAIL_PASSWORD']='xxxxxx'(好像是SMTP,我把自己的隐藏了)
app.config['FLASKY_MAIL_SUBJECT_PREFIX']='[FLASKY]'
app.config['FLASKY_MAIL_SENDER']='Flasky Admin<xxxxxxxx@qq.com>'
app.config['FLASKY_ADMIN']=os.environ.get('FLASKY_ADMIN')


玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd13679.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年05月24日 - 14时31分08秒 发布自玩蛇网

您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容
我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules