[英]Flask-Mail - Connection Refused [Errno 111]
I am using Flask-Mail in small web application. 我在小型Web应用程序中使用Flask-Mail。 Since the application is small I am using gmail to send emails.
由于应用程序很小,我使用gmail发送电子邮件。 After following all the steps in the documentation, when I run the app to test the email feature.
完成文档中的所有步骤后,运行应用程序以测试电子邮件功能。 I keep on getting a
error: [Errno 111] Connection refused
. 我继续收到
error: [Errno 111] Connection refused
。
This are my setting for email in my config.py
: 这是我在
config.py
设置电子邮件的设置:
MAIL_SERVER = 'smtp.gmail.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USERNAME = 'some_user@gmail.com'
MAIL_PASSWORD = 'some_password'
DEFAULT_MAIL_SENDER = 'some_user@gmail.com'
This is the view I am using to test Flask-Mail in my views.py
: 这是我用来在
views.py
测试Flask-Mail的视图:
@app.route('/', methods=['POST', 'GET'])
def index():
form = ContactForm()
if request.method == 'POST':
if form.validate():
msg = Message('New Msg - Test',
recipients=['some_user@gmail.com'])
msg.body = 'name=%s, email=%s \n Message:%s' % (form.name.data,
form.email.data,
form.message.data)
mail.send(msg)
flash('Message sent, I will contact you soon! Thanks')
return redirect(url_for('index'))
return render_template('index.html', form=form)
I tested to see if there were any firewall issues like this: 我测试了是否有这样的防火墙问题:
In [2]: import socket
In [3]: sock = socket.socket()
In [4]: sock.connect(("smtp.gmail.com", 587))
In [5]: sock.send("EHLO\n")
Out[5]: 5
In [6]: sock.recv(1024)
Out[6]: '220 mx.google.com ESMTP b9sm23940776vee.3 - gsmtp\r\n250-mx.google.com at your service, [108.21.9.10]\r\n250-SIZE 35882577\r\n250-8BITMIME\r\n250-STARTTLS\r\n250 ENHANCEDSTATUSCODES\r\n'
I'm not really sure about what causing the connection to be refused. 我不确定导致连接被拒绝的原因。 I would appreciate if someone can give me a push in the right direction on how to further test or point where I am making a mistake.
如果有人能够指导我如何进一步测试或指出我犯错误的地方,我将不胜感激。
I am using gmail SMTP for Flask-Mail but with the following settings. 我正在使用gmail SMTP for Flask-Mail但具有以下设置。 I use SSL with port 465. May be this will work for you ?
我在端口465上使用SSL。可能这对你有用吗?
MAIL_SERVER = 'smtp.gmail.com'
MAIL_PORT = 465
MAIL_USE_TLS = False
MAIL_USE_SSL = True
MAIL_USERNAME = 'some_user@gmail.com'
MAIL_PASSWORD = 'some_password'
DEFAULT_MAIL_SENDER = 'some_user@gmail.com'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.