A FastAPI application for sending professional emails with dynamic content using SMTP and HTML templates.
- Send emails using Gmail SMTP.
- Render HTML email templates with Jinja2.
- Send emails asynchronously in the background.
- Clone the Repository
git clone https://github.com/yourusername/fastapi-email.git
cd fastapi-email
Create and Activate a Virtual Environment
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate for Windows
Install Dependencies
pip install -r requirements.txt
Create a .env file with your Gmail SMTP credentials:
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=465
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-email-password
SENDER_EMAIL=your-email@gmail.com
- HTML Template: Located in templates/html_template.html
Start the FastAPI Server
uvicorn main:app --reload
Use the send_email_background function in main.py or integrate it into an endpoint.