diff --git a/BankServices/RoutineEmailService/app.py b/BankServices/RoutineEmailService/app.py index d6d04db..5d9aafa 100644 --- a/BankServices/RoutineEmailService/app.py +++ b/BankServices/RoutineEmailService/app.py @@ -36,7 +36,6 @@ def render_email_template( ) except Exception as e: print("Exception render template:", e) - err = e raise @@ -66,8 +65,7 @@ def send_email_to_given_address(send_to: str, html_template: str) -> bool: # Use the context manager to handle connection errors with EmailService.new_session() as email_session: # Send email through the service - EmailService.send_email(email_session, email_params) - return True + return EmailService.send_email(email_session, email_params) except Exception as e: print(f"Exception send email: {e}") return False @@ -88,10 +86,10 @@ def set_account_records_to_send_email() -> bool: account_records_query = AccountRecords.filter_all(db=db_session).query # Get the 3 most recent records - account_records: List[AccountRecords] | [] = ( + account_records: List[AccountRecords] = ( account_records_query.order_by( AccountRecords.bank_date.desc(), - AccountRecords.bank_reference_code.desc(), + AccountRecords.iban.desc(), ) .limit(3) .all() @@ -99,6 +97,7 @@ def set_account_records_to_send_email() -> bool: # Check if we have enough records if len(account_records) < 2: + print(f"Not enough records found: {len(account_records)}") return False # Check for balance discrepancy @@ -109,6 +108,7 @@ def set_account_records_to_send_email() -> bool: balance_error = expected_second_balance != second_record.bank_balance if balance_error: + print(f"Balance error detected {expected_second_balance} != {second_record.bank_balance}") return False # Format rows for the email template @@ -151,5 +151,6 @@ def set_account_records_to_send_email() -> bool: if __name__ == "__main__": success = set_account_records_to_send_email() + print("Email sent successfully" if success else "Failed to send email") exit_code = 0 if success else 1 exit(exit_code) diff --git a/Controllers/Email/config.py b/Controllers/Email/config.py index 237ff19..9ebfccd 100644 --- a/Controllers/Email/config.py +++ b/Controllers/Email/config.py @@ -10,7 +10,7 @@ class Configs(BaseSettings): USERNAME: str = "" PASSWORD: str = "" PORT: int = 0 - SEND: bool = 0 + SEND: bool = True @property def is_send(self):