Forums

ConnectionRefusedError: [Errno 111] Connection refused

Hi Everyone,

I'm using Flask/Request and Flask-Mail to generated an email from a form submitted with a ['POST'] method. I'm confused about the error I get which is :

ConnectionRefusedError: [Errno 111] Connection refused

Could anyone help me on this ? Do I have to upgrade my free account to a hacker account which would enable accessing to OVH mail system (french company : ns0.ovh.com

Here is my code :

from flask import Flask, request, render_template
from flask_mail import Mail, Message

app = Flask(__name__)
mail=Mail(app)

app.config['MAIL_SERVER']='ns0.ovh.net'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USERNAME'] = '****'
app.config['MAIL_PASSWORD'] = '*****'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = False
mail = Mail(app)

###########################################

@app.route('/')
def home_page():
    return render_template('home_page.html')

@app.route('/contribute/', methods=['POST'])
def contribute():
    #sending email
    msg = Message('[Jazz Real]', sender = 'feedback@jazzreal.org', recipients = ['feedback@jazzreal.org'])
    msg.body = 'Last Name : '+request.form['FirstName']+'\n'
    msg.body += 'First Name : '+request.form['LastName']+'\n'
    msg.body += 'Email : '+request.form['Email']+'\n'
    msg.body += 'Subject : '+request.form['Subject']+'\n'
    msg.body += 'Message : '+request.form['Message']+'\n'
    fp = request.files['file_upload']
    if fp:
        msg.attach(fp.filename,'application/octect-stream',fp.read())
        mail.send(msg)
    else: 
        mail.send(msg)
    return render_template('contribute.html')

[edit by admin: formatting]

Yes, you would need a paid account to send email using OVH's servers. Free accounts can only make HTTP/HTTPS requests to sites on our whitelist, or SMTP connections to Gmail. Paid accounts have unrestricted Internet access.