e34d56e36a
- Implemented a new n8n workflow for manual email sending, including webhook trigger, order data fetching, email building, and sending. - Added logic to format email content with customer and order details. - Introduced new columns in the sales_orders table to track email sending status. - Updated database functions to handle new rental types and email status. - Created new RPCs for updating email status and retrieving email details for sales orders.
n8n Workflows – MC Cars
This folder contains exportable n8n workflow definitions for the MC Cars qualification automation.
Workflows
01 – Qualification Payment Email
Trigger: Postgres NOTIFY on channel lead_qualified (fires when qualify_lead() creates a sales order).
Flow:
- Receives notification with
sales_order_id,customer_id, etc. - Fetches full order + customer data from Postgres.
- Sends HTML email to customer with:
- Booking summary (vehicle, dates, pricing)
- Kaution bank transfer instructions
- Payment link for the rental amount
02 – Mietvertrag PDF Email
Trigger: Same lead_qualified Postgres notification.
Flow:
- Checks if
mietvertrag_template_pathis set insite_settings. - If no template → workflow stops (no error).
- If template exists:
- Fetches customer + sales order data
- Downloads DOCX template from
document-templatesstorage bucket - Fills placeholders using JSZip (in a Code node)
- Converts filled DOCX to PDF via Gotenberg
- Sends PDF as email attachment to customer
Setup Instructions
1. Configure .env
The stack now bootstraps n8n credentials/workflow automatically on every docker compose up.
Required env variables:
POSTGRES_PASSWORDN8N_POSTGRES_CREDENTIAL_IDN8N_POSTGRES_CREDENTIAL_NAMEN8N_SMTP_CREDENTIAL_IDN8N_SMTP_CREDENTIAL_NAMEN8N_SMTP_HOSTN8N_SMTP_USERN8N_SMTP_PASSN8N_PAYPAL_KAUTION_LINKN8N_PAYPAL_MIETE_LINKN8N_PAYMENT_WORKFLOW_ID
2. Mailbox reference (for future incoming-email workflows)
- IMAP host:
heracles.mxrouting.net(port993, SSL/TLS) - POP3 host:
heracles.mxrouting.net(port995, SSL/TLS) - Username:
office@mc-cars.at - Password: same mailbox password as SMTP
3. Import behavior
On startup, n8n runs /opt/mc-cars/bootstrap/bootstrap-n8n.sh which:
- Creates/updates Postgres and SMTP credentials from
.env - Renders
01-qualification-payment-email.jsonplaceholders - Imports the workflow so nodes are always linked to the expected credential IDs
- Activates the payment workflow automatically (
n8n update:workflow --active=true)
4. Upload Mietvertrag template (optional)
- Open Admin panel → Einstellungen tab
- Upload a DOCX file in the "Mietvertrag-Vorlage" section
- The template should contain these placeholders:
| Placeholder | Replaced with |
|---|---|
{{KUNDE_NAME}} |
Customer full name |
{{KUNDE_EMAIL}} |
Customer email |
{{KUNDE_TELEFON}} |
Customer phone |
{{BESTELLNUMMER}} |
Sales order number (e.g. SO-2026-0001) |
{{FAHRZEUG}} |
Vehicle label (e.g. "Ferrari 488 GTB") |
{{DATUM_VON}} |
Rental start date (DD.MM.YYYY) |
{{DATUM_BIS}} |
Rental end date (DD.MM.YYYY) |
{{TAGE_GESAMT}} |
Total rental days |
{{WOCHENTAGE}} |
Number of weekdays |
{{WOCHENENDTAGE}} |
Number of weekend days |
{{TAGESSATZ}} |
Weekday daily subtotal |
{{WOCHENENDZUSCHLAG}} |
Weekend surcharge subtotal |
{{NETTO}} |
Net amount (excl. VAT) |
{{MWST}} |
VAT amount (19%) |
{{GESAMT}} |
Total amount (incl. VAT) |
{{KAUTION}} |
Deposit amount |
{{DATUM_HEUTE}} |
Today's date (DD.MM.YYYY) |
Dependencies
- Gotenberg (docker service
gotenberg) — converts DOCX → PDF via LibreOffice - n8n needs the
jszipnpm package (pre-installed in n8n Docker image)
Domain
All email links and sender addresses use mc-cars.at.