Python SMTP HTML Report Mailer Prompt
Generate a Python module that renders a summary report and emails it via SMTP with attachments, retries, and a dry-run mode for scheduled jobs.
- Target user
- Engineers automating nightly status and backup reports
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a senior automation engineer who ships reliable notification tooling using only the Python standard library where possible. I will provide: - The SMTP host, port, and auth method (or that creds come from env) - Recipients and the report content or a template - Whether TLS/STARTTLS is required Your job: 1. **Build the message** — use `email.message.EmailMessage`, set a plain-text fallback plus an HTML body, and attach files safely by MIME type. 2. **Load secrets from env** — never hardcode passwords; read them from environment variables and fail clearly if missing. 3. **Connect securely** — prefer STARTTLS or implicit TLS; refuse to send credentials over a plaintext connection unless explicitly forced. 4. **Retry with backoff** — wrap the send in exponential backoff with jitter for transient SMTP errors, but do not retry on auth failures. 5. **Dry-run** — `--dry-run` renders and prints the full message (headers, bodies, attachment names) without connecting. 6. **Log outcomes** — emit one structured log line per attempt with recipient count and result. 7. **Validate inputs** — reject empty recipient lists and oversized attachments early. Output as: (a) the typed module with a `send_report()` function, (b) a CLI wrapper, (c) a cron example using env-sourced credentials. Default to dry-run in examples; sending real mail must be a deliberate, credential-checked action.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Python Environment Config Drift Detector Prompt
Build a Python tool that compares configuration or environment-variable sets across environments (dev/staging/prod) and reports missing, extra, and mismatched keys while masking secret values
-
Python Multi-Log Merge and Timeline Correlator Prompt
Build a Python tool that merges several log files with different timestamp formats into one time-ordered timeline, tags each line with its source, and correlates events across services for incident analysis
-
Python Prometheus Pushgateway Batch-Job Metrics Reporter Prompt
Build a Python module that reports batch-job and cron metrics (success, duration, records processed, last-success timestamp) to a Prometheus Pushgateway with correct grouping keys and failure-safe pushing
-
Bash Nameref (declare -n) Indirect-Variable Script Prompt
Write a Bash script that uses namerefs (declare -n) to pass arrays and associative arrays into functions by reference and return structured results, replacing brittle eval-based indirection.
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.