This is a simple email sender service built with FastAPI and Python's smtplib for sending emails. It exposes an API endpoint (/api/email/send-email
) that allows you to send emails through an SMTP server (e.g., Gmail).
- Send custom emails with a subject and body
- Uses SMTP (works with Gmail, or other SMTP providers)
- Supports plain text emails
- Configurable with environment variables
- Clone this repository:
git clone https://github.com/yourusername/fastapi-emailer.git
cd fastapi-emailer
- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows, use 'venv\Scripts\activate'
(Ensure to enable it during dependency updates and utilize it as an interpreter)
- Install dependencies
pip install -r requirements.txt
- Set up environment variables (.env file):
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=youremail@gmail.com
EMAIL_HOST_PASSWORD=your_app_password
If using Gmail, generate an App Password — don't use your actual password.
- Run the FastAPI application:
uvicorn app.main:app --reload
- Access the email endpoint at:
POST /api/email/send-email
- Example Request using postman
{
"to": "recipient@example.com",
"subject": "Test Email",
"body": "Hello from Alex!"
}