From 7342516ce77cdcdfc1aeee195ad4e1a0442a6a1e Mon Sep 17 00:00:00 2001 From: Thastertyn Date: Thu, 14 Mar 2024 22:13:52 +0100 Subject: [PATCH] Fixed mail sending --- app/__init__.py | 8 ++++---- app/config.py | 5 +++-- app/services/user_service.py | 5 +---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index c3ef147..0285909 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -6,8 +6,11 @@ from flasgger import Swagger from app.doc.main_swag import main_swagger app = Flask(__name__) -jwt_manager = JWTManager(app) +from app.config import FlaskTesting, FlaskProduction +app.config.from_object(FlaskTesting) + mail = Mail(app) +jwt_manager = JWTManager(app) swag = Swagger(app, template=main_swagger) def create_app(): @@ -18,9 +21,6 @@ def create_app(): app.register_blueprint(bp_user) app.register_blueprint(bp_cart) - from app.config import FlaskTesting, FlaskProduction - app.config.from_object(FlaskTesting) - from . import jwt_utils return app \ No newline at end of file diff --git a/app/config.py b/app/config.py index 12bc616..66801d3 100644 --- a/app/config.py +++ b/app/config.py @@ -22,7 +22,8 @@ class FlaskTesting: SERVER_NAME = os.environ.get('HOST') + ':' + os.environ.get('PORT') MAIL_SERVER = os.environ.get('MAIL_SERVER') - MAIL_PORT = os.environ.get('MAIL_USERNAME') + MAIL_PORT = os.environ.get('MAIL_PORT') MAIL_USERNAME = os.environ.get('MAIL_USERNAME') MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD') - MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') \ No newline at end of file + MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') + MAIL_DEFAULT_SENDER = os.environ.get('MAIL_DEFAULT_SENDER') \ No newline at end of file diff --git a/app/services/user_service.py b/app/services/user_service.py index 4e2cb29..2e7aec1 100644 --- a/app/services/user_service.py +++ b/app/services/user_service.py @@ -62,10 +62,7 @@ class UserService: print(f"Error: {e}") return {"Failed": "Failed to insert into database. Username or email are likely in use already"}, 500 - # TODO Implement mail sending - # Currently throws error - connection refused - - # send_mail("Successfully registered!", email, "Congratulations! Your account has been successfully created.\nThis mail also serves as a test that the email address is correct") + send_mail("Successfully registered!", email, "Congratulations! Your account has been successfully created.\nThis mail also serves as a test that the email address is correct") return {"Success": "User created successfully"}, 200