🧾 Send staged invoice payment reminders with Microsoft SQL and Gmail
⚡ 52 views · 🧾 Invoice Processing
Description
Quick Overview
This workflow runs daily at 9 AM to pull unpaid invoices from Microsoft SQL, send staged payment reminder emails via Gmail based on due date timing, update invoice status and an audit log in the database, and email an HTML summary report to the finance team.
How it works
- Runs every day at 9 AM on a schedule.
- Queries a Microsoft SQL database for invoices with
PaymentStatus = 'Unpaid'and checks whether any results are returned. - For each unpaid invoice, calculates the number of days until the due date and routes it to the matching reminder window (7 days before, 3 days before, due today, 1 day overdue, 7 days overdue, or 15 days overdue).
- For invoices in each window, checks the current
ReminderStage, composes the appropriate email content, and sends the reminder to the customer via Gmail. - After each email is sent, updates the invoice record with the new
ReminderStageandLastReminderDateand inserts aREMINDER_SENTentry into a Microsoft SQLAuditLogtable. - Merges all reminder results, aggregates them into a single list, generates an HTML summary report, and emails it to the finance address via Gmail.
Setup
- Create or confirm a Microsoft SQL database schema with an
Invoicestable containing the fields used in the query and updates (includingPaymentStatus,DueDate,ReminderStage, andLastReminderDate) and anAuditLogtable for inserts. - Add Microsoft SQL credentials in n8n and verify the connection details match the server hosting your
InvoicesandAuditLogtables. - Add Gmail OAuth2 credentials in n8n with permission to send mail from the account used for customer reminders and finance summaries.
- Update the finance summary recipient email address in the final Gmail step and adjust the SQL queries and reminder email templates to match your invoice identifiers, currency, and business wording.
🔗 Nodes Used
Microsoft SQL, Gmail, Schedule Trigger
📥 Import
Download workflow.json and import into n8n:
Workflow menu → Import from File