我正在学习 Flask Web开发 。我在第6章学习时遇到的问题是我运行应用程序来测试电子邮件功能。我一直在收到错误:
socket.error: [Errno 61] Connection refused
>>> from flask.ext.mail import Message
>>> from hello import mail, app
>>> msg = Message('test subject', sender='zrron@163.com',
... recipients=['13910231836@139.com'])
>>> msg.body = 'text body'
>>> msg.html = '<b>HTML</b>body'
>>> with app.app_context():
... mail.send(msg)
#my hello.py :
import os
from flask import Flask, render_template, session
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from flask_wtf import Form
from wtforms import StringField, SubmitField
from wtforms.validators import Required
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.mail import Mail, Message
app = Flask(__name__)
Bootstrap(app)
Moment(app)
mail = Mail(app)
app.config['MAIL_SERVER'] = 'smtp.163.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_SSL'] = True #启用传输层安全
app.config['MAIL_USERNAME'] = 'xxx@163.com'
app.config['MAIL_PASSWORD'] = 'xxxxxx'
#app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME')
#app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD')
我还尝试使用app.config['MAIL_USERNAME']
并将ssl
或TLS
设置为False
,但仍然无效。
我试过很多搜索,但还没有找到解决方案。任何帮助将不胜感激。