Rule-Driven ERP Email Dispatch
Saves 8–12 hours per week by automating ERP document dispatch as PDF emails — with recipient resolution from master data, approval workflows, and per-subsidiary sender accounts.
Part of the same FastAPI portal as the document transfer pipeline — shared session manager, logging, dashboard infrastructure, and admin UI.
The Problem
Sending hundreds of ERP documents weekly by email — purchase orders to suppliers, invoices to customers, order confirmations — was fully manual. Staff either sent each document individually through the ERP's built-in email client or had to export a PDF, look up the correct recipient, compose the email in Outlook, attach the file, and send. With multiple subsidiaries and document types, this added up to thousands of emails per month.
See how much time and money a similar automation could save your team.
Calculate your automation ROIThe Approach
Core pipeline
- Recipient resolution from ERP data
- To eliminate manual address lookups and the wrong-recipient errors they caused, a single batch SQL query pulls the document, then resolves To, CC, and BCC with custom business logic — all from live ERP master data, not a separate address book.
- PDF generation via ERP print API
- The service calls the ERP's own print endpoint with the correct template, resolved through a four-level fallback chain: document output config → email template config → runtime business config → hardcoded default.
- Templated email composition
- To let business users adjust wording without involving a developer, parameterized templates per document type and language produce the subject and body. Templates are editable at runtime through an admin UI — no redeployment needed.
- Multi-account SMTP
- Each document type can have its own sender account, so every subsidiary sends from its own branded address. Accounts are managed via admin CRUD with encrypted password storage.
- ERP journal entry
- To keep the complete correspondence alongside the business document without manual filing, the system writes an outgoing-email journal entry back into the ERP document after every send — subject, body, and the PDF exactly as delivered.
- Bulk dispatch
- To turn a repetitive one-by-one task into a single confirmed action, the document list can be narrowed by practical filters so each employee sees only their own workload. Staff select individual documents or check all at once and dispatch them in a single batch — each email is sent sequentially with live progress feedback, sent rows fade out, and errors are tallied.
Automation and triggers
- Approval-flag automation
- To let staff trigger dispatch without leaving their ERP window, employees mark a document for dispatch directly inside the ERP desktop client by setting an approval field. A background scheduler picks up flagged documents on a cron schedule and sends them through the same pipeline as manual emails. If no valid recipient is found, the flag is reset and the document drops out — nothing sends silently to a wrong address.
Observability and quality control
- Master-data quality gate
- To turn email errors into a feedback loop that cleans up the master data itself, invalid or malformed recipient addresses are flagged inline with a visual indicator and the send button is disabled until the address is corrected. Because recipients are resolved from live ERP master data, fixing the address in the ERP fixes it for every future send.
- Automation summary
- After each scheduled run, the system sends a color-coded summary email to configured recipients — documents sent, skipped, and errored, with route, document number, and error detail per row. Summaries run on their own cron schedule with a managed recipient list.
- Operations dashboard
- A real-time monitoring dashboard displays KPI cards, daily activity charts, per-route distribution breakdowns, and per-user send rankings. Data older than 90 days rolls up from detail rows into pre-aggregated monthly statistics, so the same view covers daily operations and long-term trends.
- Comprehensive logging
- Every send is logged with status, timestamp, sender, recipients, user, and whether it was manual or automated. High-frequency entries are buffered and flushed asynchronously. A 90-day retention policy rolls detail rows into monthly aggregates — the database stays small but the statistics survive.
Extensibility
- Modularity and settings
- To make adding a new document type or subsidiary a config change rather than a code change, each email route is a self-contained configuration entry — sender account, recipient logic, approval field, cron schedule, and template language — all editable at runtime. The router, service layer, and automation scheduler handle new routes generically without new code paths.
Architecture
The Result
Time saved
~8–12 hours/week across all subsidiaries
Error reduction
Recipient resolution from live master data eliminates wrong-address errors
Scale
14+ active routes, hundreds of emails sent weekly
Adoption
Production since March 2026, adopted across all subsidiaries