A simple FastAPI-based service to send emails via Gmail SMTP.
- Exposes a single POST endpoint:
/send-email - Accepts JSON with
to,subject, andcontentfields - Uses Gmail SMTP (
smtp.gmail.com, port 465) for sending emails - Authenticates using environment variables:
EMAIL_ADDRESSandEMAIL_PASSWORD
- Python 3.7+
- FastAPI
- Uvicorn
pip install -r requirements.txt- Set environment variables in your shell or
.envfile:EMAIL_ADDRESS: Your Gmail addressEMAIL_PASSWORD: Your Gmail app password (see below)
- Run the app:
uvicorn main:app --host 0.0.0.0 --port 10000
- Send a POST request to
http://localhost:10000/send-email:curl -X POST http://localhost:10000/send-email \ -H "Content-Type: application/json" \ -d '{ "to": "[email protected]", "subject": "Test Email", "content": "Hello from FastAPI!" }'
- Enable 2-Step Verification in your Google Account
- Go to Security > App Passwords
- Generate an app password for "Mail"
- Use your Gmail address and the app password for authentication
- Auto-deploy from GitHub on push
- Set
EMAIL_ADDRESSandEMAIL_PASSWORDin Render's Environment Variables - Use the start command:
uvicorn main:app --host 0.0.0.0 --port 10000
- The endpoint will be available at:
https://<service-name>.onrender.com/send-email
main.py: FastAPI apprequirements.txt: Dependenciesrender.yaml: Render deployment config.gitignore: Python ignores
MIT