title: smtplib.SMTPAuthenticationError - Can't use Outlook SMTP for a forgot password feature in Flask
body: <p>I am implementing a feature where I can send a reset password email to someone in a Flask website. here's what I have in my <strong>init</strong>.py file:</p>
  <pre><code>app.config['MAIL_SERVER'] = 'smtp.office365.com'
  app.config['MAIL_PORT'] = 587
  app.config['MAIL_USE_TLS'] = True
  app.config['MAIL_USERNAME'] = 'email@organisation.org'
  app.config['MAIL_PASSWORD'] = 'password'
  mail = Mail(app)
  
  </code></pre>
  <p>Here's what I have in my routes.py file:</p>
  <pre><code>def send_rp_email(user):
      token = user.get_token()
      mess = Message('Password Reset Request', sender=&quot;email@organisation.org&quot;, recipients=[user.email])
      mess.body = f'''This email has been sent since you want to reset your password.
  If you did not request to reset your password, please ignore this email.
  {url_for('reset_token', token=token, _external=True)}'''
      mail.send(mess)
  
  @app.route('/requestpass', methods=['GET', 'POST'])
  def reset_request():
      check = check_user()
      form = RequestResetPass()
      if form.validate_on_submit():
          email = Users.query.filter_by(email=form.email.data).first()
          send_rp_email(email)
          flash('An email has been sent to your email address.', 'info')
          return redirect(url_for('login'))
      return render_template('requestrp.html', form=form)
  
  @app.route('/resetpass/&lt;token&gt;', methods=['GET', 'POST'])
  def reset_token(token):
      user = Users.verify_token(token)
      if user is None:
          flash('Invalid token', 'warning')
          return redirect(url_for('reset_request'))
      form = ResetPass()
      if form.validate_on_submit():
          hashed_pass = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
          user.password = hashed_pass
          user = Users.query.filter(Users.id == current_user.id)
          user.update({
              &quot;password&quot;: hashed_pass
          })
          db.session.commit()
          return redirect(url_for('login'))
      return render_template('resetpass.html', form=form)
  </code></pre>
  <p>I am getting this error whenever I submit an email address to send the email through:</p>
  <pre><code>smtplib.SMTPAuthenticationError: (535, b'5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator.
  </code></pre>