Files
OSIT-AE-API-FastAPI/app/routers/util_email.py
Scott Idem 8eb699efe5 refactor(routers): comment out legacy endpoints across multiple routers
Disabled legacy routes that are superseded by V3 equivalents. Code is
commented out (not deleted) pending final verification and cleanup pass.

- registry.py: remove sql, lookup (/lu), websockets, websockets_redis;
  clean up dead imports (contact, event_person, etc.)
- data_store.py: comment out legacy CRUD and code-lookup endpoints;
  keep V3 code-lookup routes active; add TODO for action path rename
- api.py: comment out Api_Base CRUD, get_id (internal ID leak),
  and sql_test (debug) endpoints
- aether_cfg.py: comment out legacy Flask cfg endpoint
- user.py: comment out legacy user endpoints
- util_email.py: minor cleanup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-24 19:22:45 -04:00

90 lines
3.1 KiB
Python

import datetime, pytz, time
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Path, Query, Response, status
from pydantic import BaseModel, EmailStr, Field
from typing import Dict, List, Optional, Set, Union
from app.lib_general import log, logging, common_route_params, Common_Route_Params, send_email
from app.config import settings
from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, get_id_random, redis_lookup_id_random
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
from app.methods.data_store_methods import create_update_data_store_obj, get_data_store_rec_list, load_data_store_obj, load_data_store_obj_w_code
from app.models.util_email_models import Email_Send_Base
from app.models.response_models import Resp_Body_Base, mk_resp
router = APIRouter()
# ### BEGIN ### API Utility: Email ### util_email_send_obj() ###
# Updated 2023-06-27
# NOTE: This is actively in use 2026-03-24 -Scott
# This is marked for deprecation and must be migrated to Aether API v3 standards!
@router.post('/util/email/send', response_model=Resp_Body_Base)
async def util_email_send_obj(
email_send_obj: Email_Send_Base,
test: Optional[bool] = False,
return_obj: bool = True,
commons: Common_Route_Params = Depends(common_route_params),
):
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
resp_data = {}
from_email = email_send_obj.from_email
resp_data['from_email'] = from_email
from_name = email_send_obj.from_name
to_email = email_send_obj.to_email
resp_data['to_email'] = to_email
to_name = email_send_obj.to_name
bcc_email = email_send_obj.bcc_email
bcc_name = email_send_obj.bcc_name
subject = email_send_obj.subject
resp_data['subject'] = subject[:20]
body_html = email_send_obj.body_html
body_text = email_send_obj.body_text
log.info('Trying send_email()...')
# NOTE: This all works, but I think it could be done better???
if send_email(
from_email = from_email,
from_name = from_name,
to_email = to_email,
to_name = to_name,
bcc_email = bcc_email,
bcc_name = bcc_name,
subject = subject,
body_text = body_text,
body_html = body_html,
test = test
):
status_code = 200
status_message = f'Email was sent to <{to_email}>.'
else:
status_code = 400
status_message = f'Email failed to send to <{to_email}>.'
log.info(status_message)
if return_obj:
return mk_resp(data=resp_data, status_code=status_code, response=commons.response, status_message=status_message)
else:
if status_code == 200:
resp_data = True
else:
resp_data = False
return mk_resp(data=resp_data, status_code=status_code, response=commons.response, status_message=status_message)
# ### END ### API Utility: Email ### util_email_send_obj() ###