Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Beginner ClaudeChatGPT

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

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.