Skip to content

Add due_date email reminders using FastAPI BackgroundTasks #14

Description

@Navashub

Description

When a task's due_date is within 24 hours, send the task owner an email reminder. Use FastAPI's built-in BackgroundTasks so it doesn't block the request.

What to do

  • This issue depends on Issue Add due_date field to Task #2 (due_date field) being merged first
  • Create a notifications.py module with a send_reminder_email(to: str, task_title: str) function using smtplib or the Resend API
  • Add a POST /tasks/send-reminders endpoint (admin-style) that:
    • Queries all incomplete tasks where due_date is within the next 24 hours
    • Fires a background email for each one via BackgroundTasks
    • Returns { "queued": N } immediately without waiting for emails to send
  • Read SMTP credentials from .env
  • Add a note in .env.example for the required email vars

Acceptance Criteria

  • The endpoint returns immediately (does not wait for emails)
  • Background tasks fire after the response is returned
  • Email credentials are never hardcoded

Hints

from fastapi import BackgroundTasks

@router.post("/send-reminders")
def send_reminders(background_tasks: BackgroundTasks, db: Session = Depends(get_db)):
    tasks = get_due_soon(db)
    for task in tasks:
        background_tasks.add_task(send_reminder_email, task.owner.email, task.title)
    return {"queued": len(tasks)}

Difficulty

🔴 Advanced

Metadata

Metadata

Assignees

No one assigned

    Labels

    advancedAuth, testing, DevOpsbackendPython / FastAPI work

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions