有什么办法可以在Flask中外部配置邮件?

时间:2019-12-13 14:58:24

标签: python python-3.x flask

由于我们使用.yaml文件进行数据库配置

db = yaml.load(open('db.yaml'))
app.config['MYSQL_HOST'] = db['mysql_host']
app.config['MYSQL_USER'] = db['mysql_user']
app.config['MYSQL_PASSWORD'] = db['mysql_password']
app.config['MYSQL_DB'] = db['mysql_db']

有什么方法可以配置邮件?

#mail_config
app.config['DEBUG']=True
app.config['TESTING'] = False
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT']=465
app.config['MAIL_USE_SSL']=True
app.config['MAIL_USE_TLS']=False
app.config['MAIL_USERNAME'] = '*********@gmail.com'
app.config['MAIL_PASSWORD']= '****************'                         #app password for gmail
app.config['MAIL_DEFAULT_SENDER'] = '***********@gmail.com'
app.config['MAIL_ASCII_ATTACHMENTS'] = False
#mail_config

1 个答案:

答案 0 :(得分:0)

Flask-mail为您提供了一种现成的解决方案。 不过,您将需要邮件提供商的详细信息。

这是文档 https://pythonhosted.org/Flask-Mail/