3

I'm sending password reset email with Flask-Mail. When I tried it on development server everything works fine. When deployed on Ubuntu (using NGINX, Gunicorn) sending the email leads after a long loading time to Error 502 so I don't think there's problem in sending the email rather there's a problem in the settings.

My init code after deploying:

import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
from flask_mail import Mail
from flask_socketio import SocketIO

import json

with open('/etc/config.json') as config_file:
    config = json.load(config_file)

app = Flask(__name__)
app.config['SECRET_KEY'] = config.get('SECRET_KEY')
app.config['SQLALCHEMY_DATABASE_URI'] = config.get('SQLALCHEMY_DATABASE_URI')
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = config.get('EMAIL_USER')
app.config['MAIL_PASSWORD'] = config.get('EMAIL_PASS')
mail = Mail(app)

In config.json the information is correctly provided

Aaku
  • 7
  • 2
Thomas
  • 31
  • 3

2 Answers2

0

Disabling CAPTCHA for clients If you are not using 2-factor authentication and you have verified the credentials in your Python source are correct, follow these steps:

1.) Login to gmail in your browser

2.) Navigate to the DisplayUnclockCaptcha page.

3.) Click the continue button, and you will see the message 'Account access enabled Please try signing in to your Google account again from your new device or application.'

4.)Run your Python script - your login attempt should be successful.

Community
  • 1
  • 1
0

Hello i might be a little late for this, but thomas your problem is caused because of linode which is probably the deployment server that you used, decided to default block the ports that you are using as you can see it here. https://www.linode.com/community/questions/19082/i-just-created-my-first-linode-and-i-cant-send-emails-why if u follow the process given it certainly will work

INGl0R1AM0R1
  • 1,532
  • 5
  • 16