By
Russell Taylor
If your business sends invoices, you know how challenging it can be to get customers to pay on time. Missed or late payments can disrupt cash flow and create extra work for teams. The good news? You can build an automated payment reminder system that handles both physical letters and email follow-ups without manual effort.
This tutorial walks you through creating a Node.js payment reminder system that automatically sends printed letters through Lob's Letter API and follow-up emails via Customer.io, all triggered by customer events tracked in Segment. By the end, you'll have a system that catches overdue payments before they become bigger problems.
Your automated payment reminder system will work like this: when a payment becomes overdue, the system automatically generates a personalized letter, prints and mails it through Lob, then tracks that event in Segment. Customer.io picks up that event and sends a follow-up email a few days later.
The system uses three main components working together. Node.js acts as the central hub that processes customer data and triggers actions. The Lob Letter API handles the physical mail creation and delivery. Segment tracks all the events and connects your data to Customer.io for email automation.
Here's what happens behind the scenes: your application identifies customers with overdue payments, creates personalized letters with their specific details, sends those letters for printing and mailing, logs the activity in Segment, and triggers automated email sequences in Customer.io based on that activity.
You'll use several tools to build this automated billing notification system:
You'll also need accounts with API access for each service, plus a text editor and internet connection.
Start by creating a new Node.js project and installing the required packages:
bash
npm init
npm install --save analytics-node lob dotenv
Create a .env
file in your project root to store your API credentials securely:
LOB_API_KEY=your-lob-api-key
SEGMENT_WRITE_KEY=your-segment-write-key
CUSTOMER_IO_API_KEY=your-customerio-api-key
At the top of your main JavaScript file, load these environment variables:
javascript
require('dotenv').config();
const Lob = require('lob');
const Analytics = require('analytics-node');
const lob = new Lob(process.env.LOB_API_KEY);
const analytics = new Analytics(process.env.SEGMENT_WRITE_KEY);
This setup gives your application access to all three services while keeping your credentials secure.
Your payment reminder system works with customer records that include both mailing address and payment information. Here's how to structure the data:
javascript
const customer = {
firstName: "Alex",
lastName: "Rivera",
email: "alex.rivera@email.com",
addressLine1: "123 Main St",
city: "San Francisco",
state: "CA",
zip: "94105",
invoiceId: "INV-20250805-001",
amountDue: "150.00",
paymentDueDate: "2025-08-15"
};
This data structure works across all three platforms. The address fields map directly to Lob's Letter API requirements, while the payment details flow through Segment to Customer.io for email personalization.
When you're pulling this data from your billing system, make sure each record includes complete address information and current payment status. Missing fields will cause API errors or incomplete communications.
The Lob Letter API uses HTML templates with placeholder variables for personalization. Create a simple but professional template:
html
<html>
<head>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
.header { font-size: 22px; font-weight: bold; margin-bottom: 20px; }
.details { margin: 20px 0; }
.amount { font-size: 18px; font-weight: bold; color: #d32f2f; }
</style>
</head>
<body>
<div class="header">Payment Reminder</div>
<div class="details">
<p>Dear {{firstName}} {{lastName}},</p>
<p>Your payment of <span class="amount">${{amountDue}}</span> [for invoice](https://www.lob.com/tags/invoices) {{invoiceId}} was due on {{paymentDueDate}}.</p>
<p>Please submit your payment to avoid additional fees.</p>
<p>If you've already paid, please disregard [this notice](https://www.lob.com/tags/notices).</p>
</div>
</body>
</html>
The double curly braces create placeholders that Lob fills with actual customer data when printing each letter. You can customize the styling, add your company logo, or include additional payment instructions as needed.
Here's how to send payment reminder letters using the Lob Letter API:
javascript
function sendPaymentReminder(customer) {
const letterTemplate = `
<html>
<body style="font-family: Arial, sans-serif; margin: 40px;">
<h2>Payment Reminder</h2>
<p>Dear ${customer.firstName} ${customer.lastName},</p>
<p>Your payment of $${customer.amountDue} for invoice ${customer.invoiceId} was due on ${customer.paymentDueDate}.</p>
<p>Please submit your payment to avoid additional fees.</p>
</body>
</html>
`;
lob.letters.create({
description: `Payment Reminder - ${customer.invoiceId}`,
to: {
name: `${customer.firstName} ${customer.lastName}`,
address_line1: customer.addressLine1,
address_city: customer.city,
address_state: customer.state,
address_zip: customer.zip,
address_country: 'US'
},
from: {
name: 'Your Business Name',
address_line1: '456 Business Ave',
address_city: 'San Francisco',
address_state: 'CA',
address_zip: '94107',
address_country: 'US'
},
file: letterTemplate,
color: false
}, function (err, letter) {
if (err) {
console.error('Letter creation failed:', err);
} else {
console.log('Letter queued for printing:', letter.id);
trackReminderEvent(customer, letter.id);
}
});
}
This function creates a personalized letter for each customer and sends it to Lob for printing and mailing. The API returns a unique letter ID that you can use for tracking.
After sending each letter, log the activity in Segment so Customer.io can trigger follow-up emails:
javascript
function trackReminderEvent(customer, letterId) {
analytics.track({
userId: customer.email,
event: 'Payment Reminder Sent',
properties: {
channel: 'Direct Mail',
invoiceId: customer.invoiceId,
amountDue: customer.amountDue,
paymentDueDate: customer.paymentDueDate,
letterId: letterId,
sentAt: new Date().toISOString()
}
});
}
This event data flows from Segment to Customer.io, where you can set up automated email campaigns that respond to payment reminder activities. The properties include all the details needed for personalized follow-up messages.
In Customer.io, create a new campaign triggered by the "Payment Reminder Sent" event from Segment:
Campaign Setup:
Email Content:
Hello {{customer.first_name}},
We recently mailed a payment reminder for invoice {{invoice_id}}.
Amount due: ${{amount_due}}
Original due date: {{payment_due_date}}
Please submit your payment online or contact us if you have questions.
Thank you,
Accounts Receivable Team
Customer.io automatically personalizes each email using the event properties sent through Segment. This creates a seamless follow-up sequence where customers receive both physical and digital reminders.
Testing ensures all components work together correctly. Start with a sample customer record and process it through your system:
javascript
const testCustomer = {
firstName: "Jane",
lastName: "Smith",
email: "jane.smith@email.com",
addressLine1: "789 Test St",
city: "Austin",
state: "TX",
zip: "78701",
invoiceId: "TEST-001",
amountDue: "75.00",
paymentDueDate: "2025-08-01"
};
sendPaymentReminder(testCustomer);
Check these results after running your test:
If any step fails, review your API credentials and data formatting. Each service provides detailed error messages to help troubleshoot issues.
Building an automated payment reminder system connects three powerful tools to handle both physical and digital communications. Node.js processes your customer data and orchestrates the workflow. The Lob Letter API creates professional payment reminder letters that get mailed automatically. Segment tracks all the activity and triggers follow-up emails through Customer.io.
This approach reduces manual work while improving payment collection rates. Customers receive timely reminders through multiple channels, and you get detailed tracking of every interaction. The system scales with your business and adapts to different payment scenarios.
Ready to automate your payment reminders? Book a demo with Lob to see how our Letter API can streamline your billing communications and improve cash flow.
How long does it take for Lob to print and mail payment reminder letters?
Lob's Print Delivery Network gets your letters printed and in the mail within 1-2 business days — that's the speed of digital with the impact of physical mail. Letters submitted before 2 PM EST typically go out the same day.
Can I customize the letter design beyond basic HTML formatting?
Yes, the Lob Letter API supports full HTML and CSS styling, including custom fonts, colors, images, and layouts. You can create professional-looking letters that match your brand guidelines using standard web technologies.
What happens if a customer's mailing address is invalid or incomplete?
Lob validates addresses during the API call and returns an error for invalid addresses before printing. You can catch these errors in your code and either correct the address or skip that customer and log the issue for manual review.
How do I stop email reminders if a customer pays after the letter is sent?
Update the customer's payment status in your system and send a "Payment Received" event to Segment. In Customer.io, create campaign rules that cancel or skip email sends when this event occurs for the same invoice.