Guide
Send Payment Reminder Emails from CLI
You need to chase unpaid invoices without buying your billing platform's email add-on. This guide schedules dunning emails with one command, gates each send on a live invoice status check in a bash script, and cancels the reminder the moment the invoice is marked paid.
Written by Nick Barraclough Product Manager
Reviewed by Qasim Muhammad
How do I send a payment reminder email from the terminal?
Send a payment reminder email by passing the customer address, a subject, and the overdue amount to nylas email send. Delivery goes over your connected provider's API, so there is no SMTP host, port, or app password to configure. The --yes flag skips the confirmation prompt so the command runs unattended in a cron job.
nylas email send \
--to ada@acme.com \
--subject "Invoice INV-1042 is 7 days overdue" \
--body "Hi Ada, invoice INV-1042 for \$480.00 was due on 2026-06-02. Please pay at your earliest convenience." \
--metadata invoice_id=INV-1042 \
--yesThat one command replaces the email add-on most billing platforms sell as a paid tier. It works the same across Gmail, Outlook, and any IMAP account, so a single script chases invoices regardless of which mailbox sends them. The --metadata pair tags the message with the invoice ID for later correlation.
How do I schedule a dunning email for a future date?
Schedule a dunning email with the --schedule flag, which accepts a relative duration like 3d, a clock time like 9am, or an absolute date. Nylas holds the message and sends it at that time, so a single command queues a reminder days ahead without keeping a process running.
# Queue a first reminder 3 days from now
nylas email send \
--to ada@acme.com \
--subject "Reminder: invoice INV-1042 due soon" \
--body "Hi Ada, invoice INV-1042 for \$480.00 is due 2026-06-02." \
--metadata invoice_id=INV-1042 \
--schedule 3d \
--yesA classic dunning ladder sends three reminders — for example at 3, 7, and 14 days past due — with the tone escalating each time. Queue all three at once, then list pending sends with nylas email scheduled list to confirm they are in the queue before you walk away.
How do I stop a reminder if the invoice is already paid?
Gate the send on a live status check: call your billing API, read the invoice state, and only run nylas email send when the status is still unpaid. This single conditional is what separates a useful reminder from the embarrassing mistake of dunning a customer who settled the bill an hour ago.
#!/usr/bin/env bash
set -euo pipefail
INVOICE_ID="INV-1042"
CUSTOMER="ada@acme.com"
# Ask your billing system for the current status (returns "paid" or "open")
STATUS=$(curl -fsSL \
-H "Authorization: Bearer $BILLING_TOKEN" \
"https://api.billing.example.com/invoices/$INVOICE_ID" \
| jq -r '.status')
if [ "$STATUS" = "open" ]; then
nylas email send --to "$CUSTOMER" \
--subject "Invoice $INVOICE_ID is overdue" \
--body "Your invoice $INVOICE_ID remains unpaid. Please settle it today." \
--metadata invoice_id="$INVOICE_ID" --yes
else
echo "Invoice $INVOICE_ID is $STATUS — skipping reminder"
fiRun this script from cron on a daily cadence. Because the status read happens at send time, a customer who paid yesterday gets nothing today. The set -euo pipefail line makes the script exit on the first error, so a failed API call never silently sends the wrong reminder.
How do I cancel a scheduled reminder when payment arrives?
Cancel a queued reminder with nylas email scheduled cancel and the schedule ID. When a webhook or a status poll tells you an invoice was paid, pull the pending sends, find the one tagged with that invoice, and cancel it. This closes the gap where a reminder is already in the queue before payment lands.
# List pending scheduled sends as JSON, then cancel by ID
SCHEDULE_ID=$(nylas email scheduled list --json \
| jq -r '.[0].schedule_id')
nylas email scheduled cancel "$SCHEDULE_ID" --forceThe --force flag skips the confirmation prompt so the cancel runs inside an automated payment-received handler. Together with the status gate, this gives two layers of protection: the gate stops new sends, and the cancel pulls back reminders already scheduled for the next 14 days.
What should a dunning email say, and what are the limits?
A payment reminder email should state the invoice number, the amount, the original due date, and a single clear payment action. Keep early reminders friendly; reserve firm language for the final notice. Reusable copy belongs in a stored template so the wording stays consistent across every invoice and every teammate who triggers a send.
# Render a hosted template with invoice data instead of inline copy
nylas email send --to ada@acme.com \
--template-id tpl_dunning_overdue \
--template-data '{"invoice":"INV-1042","amount":"$480.00","due":"2026-06-02"}' \
--metadata invoice_id=INV-1042 --yesKnow the legal line. If you collect debts on behalf of others in the United States, the FDCPA (Regulation F) governs frequency and content. A business chasing its own invoices is usually outside that scope, but the rule's 7-in-7-days contact limit is a sensible ceiling to respect anyway. When you send bulk reminders, include a one-click unsubscribe header per RFC 8058 to protect sender reputation.
Next steps
- Send Yourself Follow-Up Reminders — Find sent threads with no reply via nylas email threads and…
- Send email from a bash script — the scripting patterns behind the status-gated send above
- Schedule email from the terminal — full reference for
--scheduletiming and canceling queued sends - Email templates from the CLI — keep dunning copy consistent across every invoice
- Tag emails with metadata — correlate each reminder to its invoice ID for reporting
- Getting started with Nylas CLI — connect your first account in under 5 minutes
- Command reference — every flag, subcommand, and example
- CFPB Regulation F — the debt-collection rule that bounds frequency and content
- Gmail API documentation — the provider API the CLI sends over for Gmail accounts