Automate Customer Invoicing and Notifications with n8n
Overview
This n8n workflow template automates two common customer communication tasks:
- Sending individualized, text-based invoice emails to each customer.
- Sending a consolidated HTML summary email listing all new customers.
The automation retrieves customer records from a datastore, enriches each item with invoice line items, generates documents from templates, and dispatches emails to both customers and internal recipients. The workflow is designed for manual execution, which is useful for controlled batch runs, testing, or on-demand invoicing.
Workflow Architecture
At a high level, the workflow follows this sequence:
- Manual trigger – Start the workflow only when explicitly executed.
- Customer data retrieval – Fetch all customer records using the datastore node with the
getAllPeopleoperation. - Sorting – Alphabetically sort the customer list by name for consistent output.
- Invoice enrichment – Use a Function Item node to attach invoice line items and metadata to each customer.
- Per-customer document generation – Generate one text-based invoice document per customer from a template.
- Per-customer email sending – Email each generated invoice to the corresponding customer.
- Consolidated document generation – Create a single HTML document listing all customers as a summary.
- Summary email sending – Send the HTML summary to an internal recipient, such as an admin or finance team.
Data Flow and Node Responsibilities
The workflow processes data as an item stream. Each customer record is treated as an individual item that is transformed and enriched as it moves through the nodes. In parallel, the same item list is also used to build an aggregated HTML output for internal reporting.
Node-by-Node Breakdown
1. Manual Trigger Node
Purpose: Start the workflow only when you explicitly click Execute in the n8n editor.
- Node type: Manual Trigger
- Trigger behavior: No schedule or external webhook. The workflow runs only on manual execution.
This is useful when:
- You want full control over when invoices and notifications are sent.
- You are testing or iterating on the workflow configuration.
2. Customer Datastore Node
Purpose: Retrieve all customer records from your configured datastore.
- Node type: Datastore (or equivalent database integration used in the template).
- Operation:
getAllPeople
The node returns a list of customer items. Each item typically includes:
name– Customer full name.email– Customer email address.locationor similar fields – Additional metadata used for personalization or internal reporting.
Configuration notes:
- Ensure datastore credentials are configured in n8n before running the workflow.
- Verify that the
getAllPeopleoperation returns the fields referenced later in templates, especiallynameandemail.
3. Item Lists Node (Sorting)
Purpose: Sort the list of customers alphabetically by name to produce consistent and predictable output.
- Node type: Item Lists
- Key action: Sort items by the
namefield in ascending order.
Sorting improves:
- Readability of the summary email.
- Traceability when comparing generated emails with the underlying customer list.
Edge case: If a customer record is missing the name field or has it set to null, n8n will still attempt to sort but the position of such items may be unexpected. For consistent behavior, ensure that all customers have a valid name value.
4. Function Item Node – Add Invoice Lines
Purpose: Enrich each customer item with invoice-specific data, including line items and invoice-level metadata.
- Node type: Function Item
- Scope: Processes one item at a time and returns the modified item.
Inside this node, a custom JavaScript function:
- Adds example invoice line items, such as two predefined services.
- Sets fields like:
descriptionquantityamountVATtotalper line item
- Calculates and sets the overall invoice total for each customer.
- Defines an
invoiceDateor similar field that is later referenced in the document template.
Configuration notes:
- Ensure property names used here match the placeholders in the document templates.
- Adjust line items, VAT logic, and total calculations as needed for your billing model.
5. Document Generation Node – One Item Per Template
Purpose: Generate a personalized text invoice for each customer using a template.
- Node type: Document Generation (or similar template node).
- Mode: One item per template.
- Output format: Text (plain text invoice body).
The template typically includes:
- Invoice date and customer name.
- Recipient details such as email or location, if included in the template.
- A detailed list of service line items with description, quantity, price, VAT, and total.
- A final invoice total derived from the Function Item node.
Each incoming item (customer) results in one generated text document. That document is then attached to the item and passed to the next node for email delivery.
6. Email Node – Send One TEXT Email Per Item
Purpose: Send the generated invoice text to each customer as a personalized email.
- Node type: Email (e.g., SMTP or specific email integration).
- Mode: One email per incoming item.
Typical configuration:
- To: Expression referencing the customer’s
emailfield. - Subject: Dynamic, often including the customer’s
nameor invoice date. - Body: The generated text document from the previous node.
- Format: Plain text email body, suitable for simple invoice communication.
Error handling considerations:
- If a customer item is missing an
emailaddress, the email node may fail for that item. Consider validating the email field upstream or adding conditional logic to skip incomplete records. - Ensure email credentials (SMTP or service-specific) are correctly configured and tested in n8n before running the workflow for production.
7. Document Generation Node – All Items, One Template
Purpose: Build a single HTML document that lists all customers in a consolidated format.
- Node type: Document Generation (or similar template node).
- Mode: All items, one template.
- Output format: HTML.
This node receives the full list of customer items and produces one aggregated HTML output. The template typically:
- Iterates over all customers.
- Renders each customer as a list entry, usually with:
- Name
- Email address
- Wraps the list in standard HTML markup, for example an unordered list.
The result is a clean, readable summary of all new or processed customers, suitable for internal reporting.
8. Email Node – Send One HTML Email Per List
Purpose: Send the consolidated HTML summary to a designated internal recipient.
- Node type: Email.
- Mode: One email for the entire list.
Typical configuration:
- To: A fixed address, such as an admin, finance, or sales operations mailbox.
- Subject: A static or partially dynamic subject such as “New Customers Summary”.
- Body: The generated HTML summary from the previous node.
- Format: HTML email, so the bullet list and formatting render correctly in email clients.
Configuration Notes and Prerequisites
Credentials and Integrations
- Datastore credentials: Required for the
getAllPeopleoperation. Confirm that the node can successfully read from your datastore. - Email credentials: Configure SMTP or your chosen email integration in n8n and test with a simple workflow before using this template in production.
Template Alignment
To avoid runtime issues, ensure the following:
- Field names produced by the Function Item node (for example,
invoiceLines,invoiceDate,total) exactly match the placeholders defined in the document templates. - The customer fields used in templates, such as
nameandemail, exist in the output of the datastore node.
Handling Missing or Invalid Data
- If some customers lack email addresses, you may want to:
- Filter them out before the email node, or
- Add validation logic in the Function Item node.
- If names or other key fields are missing, consider default values or an upstream data quality check.
Use Cases and Benefits
Primary Use Cases
- Personalized automated billing: Generate and send itemized invoices to each customer without manual formatting or copy-paste work.
- New customer notifications: Keep internal teams informed about newly added or processed customers through a single consolidated summary email.
Key Benefits
- Reduced manual effort: Replace repetitive email drafting with an automated, repeatable workflow.
- Consistency and accuracy: Use the same templates and logic for every run, which reduces formatting errors and missing details.
- Customizable templates: Adjust document generator templates to reflect your branding, tone, and invoice layout.
- Scalable automation: Run the workflow daily, weekly, or on demand, depending on your billing and notification cycles.
Advanced Customization Ideas
Once the base template is working, you can extend or adapt it:
- Scheduling: Replace the Manual Trigger with a Cron node if you want fully automated daily or weekly invoice runs.
- Additional filters: Insert a Filter or IF node after data retrieval to send invoices only to specific customer segments.
- Different invoice structures: Modify the Function Item logic to support discounts, multiple tax rates, or different currencies.
- Alternative channels: Duplicate the email branch to send invoices through another integration (for example, a ticketing or CRM system) if supported by your n8n setup.
Getting Started
To start using this automation in your own n8n environment:
- Import or open the provided workflow template.
- Configure datastore and email credentials in n8n.
- Review and adjust the Function Item logic and document templates to match your invoice format and branding.
- Run the workflow manually using the Manual Trigger to validate behavior and outputs.
- Once tested, optionally add scheduling or additional logic based on your business requirements.
By connecting your data sources, defining clear templates, and automating email delivery, you can significantly streamline customer invoicing and internal notifications.
Call to Action
Ready to reduce manual invoicing work and improve consistency in customer communication? Start with this n8n workflow template, adapt it to your data and templates, and automate personalized invoices and summary notifications with confidence.
