How do I resolve builtins.ConnectionRefusedError error in attempting to send email using flask-mail
<p>I am making a simple WebApp using Flask framework in python. It will take user inputs for email and name from my website (<a href="http://www.anshulbansal.esy.es" rel="nofollow">www.anshulbansal.esy.es</a>) and will check if email exists in database (here database is supposed as dictionary for now) then it will not work further, but if it doesn't exists in database, it will send a random link to the submitted email and if the user clicks the link, then its info will be added to my database.</p>

<p>It's almost done but this error in coming in my way. Check out this code:  </p>

<pre><code>from flask import Flask, render_template, request, redirect, url_for
from flask_mail import Mail, Message
import random
import string


def random_generator(size=6, chars=string.ascii_letters + string.digits):
    return ''.join(random.choice(chars) for x in range(size))


subscribers_d = {'anshul.bansal5@yahoo.com': 'Anshul Bansal', 'anshul.bansal3@yahoo.com': 'Bansal', 'anshul.bansal@yahoo.com': 'Anshul',}

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

app.config.update(
    MAIL_SERVER='smtp.gmail.com',
    MAIL_PORT=465,
    MAIL_USE_TLS = False,
    MAIL_USE_SSL=True,
    MAIL_USERNAME='anshul.bansal950@gmail.com',
    MAIL_PASSWORD="It's Secret"
)


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


@app.route('/submit', methods=['POST'])
def submit():
    if request.method == "POST":
        v_name = request.form['vname']
        v_email = request.form['vemail']
        return send_mail(v_name, v_email)
    else:
        return redirect(url_for("/"))

random_link_sent = random_generator(20)


@app.route("/")
def send_mail(v_name, v_email):
    if v_email in subscribers_d:
        return "Oh! It seems that you have already registered."
    else:
        msg = Message('Confirm Subscription', sender=['anshul.bansal950@gmail.com'], recipients=[v_email])
        msg.html = "&lt;h3&gt;Confirm Subscription&lt;/h3&gt;" \
           "&lt;p&gt;Hi! &lt;/p&gt;" + v_name + "&lt;p&gt; , Please click on below link to subscribe&lt;/p&gt;" \
            "Link: " + ' www.anshulbansal.esy.es/' + random_link_sent
        mail.send(msg)
        return 'Check Your Inbox For Confirmation Email'


@app.route("/&lt;random_link_sent&gt;")
def confirm(random_link_sent):
    return "You have registered on " + random_link_sent
    subscribers_d[v_email] = v_name


if __name__ == "__main__":
    app.run(debug=True)
</code></pre>

<p>But this code is giving me a builtins.ConnectionRefusedError Error. 
But before 2-3 attempts of sending email were successful without any error.
How do I resolve it?</p>

<p><a href="http://i.stack.imgur.com/cJNKS.png" rel="nofollow">Here is the screenshot of error</a></p>

<p>You should update configuration before you initialize Mail:</p>

<pre><code>app = Flask(__name__)

app.config.update(
    DEBUG = True,
    MAIL_SERVER = 'smtp.gmail.com',
    MAIL_PORT = 587,
    MAIL_USE_TLS = True,
    MAIL_USE_SSL = False,
    MAIL_USERNAME = 'your_username@gmail.com',
    MAIL_PASSWORD = 'your_password',
)

mail = Mail(app)
</code></pre>

python email flask flask-mail