title: How can I resolve ConnectionRefusedError in Flask?
body: <p>I'm trying to add the ability to reset a user's password with a password reset link with Flask but whenever I go to test out the functionality of this feature, I'm met with ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it.</p>
  <p>Here's the revelant snippets of code from my app.py and <strong>init</strong>.py. If this isn't enough to solve the problem, just let me know what else you need to see.</p>
  <p>app.py</p>
  <pre><code>def send_reset_email(user):
  token = user.get_reset_token()
  msg = Message('Password Reset Request')
  msg.sender = 'noreply@demo.com'
  msg.recipients = [user.email]
  msg.body = f&quot;&quot;&quot;
  To reset your password, visit the following link: {url_for('reset_token', token=token, _external=True)}. 
  If you did not make this request, then ignore this email and no changes will be made.
  &quot;&quot;&quot;
  mail.send(msg)
  
  
  @app.route(&quot;/reset_password&quot;, methods=['GET', 'POST'])
  def reset_password():
  if current_user.is_authenticated:
      return redirect(url_for('home'))
  form = RequestResetForm()
  if form.validate_on_submit():
      user = User.query.filter_by(email=form.email.data).first()
      send_reset_email(user)
      flash('An email has been set with instructions to reset your password.', 'info')
      return redirect(url_for('login'))
  return render_template('reset_request.html', title='Reset Password', form=form)
  </code></pre>
  <p><strong>init</strong>.py</p>
  <pre><code>app = Flask(__name__)
  db = SQLAlchemy(app)
  bcrypt = Bcrypt(app)
  login_manager = LoginManager(app)
  login_manager.login_view = 'login'
  login_manager.login_message_category = 'info'
  mail = Mail()
  mail.init_app(app)
  
  app.config['SECRET_KEY'] = 'f645748071241866b90c405a391033ac'
  app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
  app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
  app.config['MAIL_SERVER'] = 'smtp.gmail.com'
  app.config['MAIL_PORT'] = 587
  app.config['MAIL_USE_TLS'] = True
  app.config['MAIL_USERNAME'] = os.environ.get('EMAIL_USER')
  app.config['MAIL_PASSWORD'] = os.environ.get('EMAIL_USER')
  app.config['MAIL_SUPPRESS_SEND'] = False
  </code></pre>