Email automation for the payment request

Hello everyone,

I’m looking for a way to automate email notifications to customers regarding their outstanding payments. Specifically, I want the system to:

  • Send an email reminder if the payment becomes overdue.

To automate email reminders for overdue payments in Frappe ERPNext, you can use a Scheduled Job combined with Email Templates and a custom script. Below is a complete guide to implement this:


:white_check_mark: Goal

Automatically send email reminders to customers when their Sales Invoices are overdue.


:white_check_mark: Step-by-Step Implementation

1. Create an Email Template

Go to:

Email Template → New

Fill the details:

  • Name: Overdue Payment Reminder
  • Subject: Reminder: Payment Overdue for Invoice {{ doc.name }}
  • Message (example):
Dear {{ doc.customer_name }},

This is a friendly reminder that your payment for Invoice {{ doc.name }} is overdue.

**Invoice Date**: {{ doc.posting_date }}  
**Due Date**: {{ doc.due_date }}  
**Outstanding Amount**: ₹{{ doc.outstanding_amount }}

We request you to kindly make the payment at the earliest.

Regards,  
Accounts Team  

2. Write a Scheduled Job

Create a Python script in your custom app, e.g., hooks.py and overdue_reminder.py.

hooks.py

scheduler_events = {
    "daily": [
        "your_app.overdue_reminder.send_overdue_reminders"
    ]
}

your_app/overdue_reminder.py

import frappe
from frappe.utils import nowdate

def send_overdue_reminders():
    overdue_invoices = frappe.get_all(
        "Sales Invoice",
        filters={
            "outstanding_amount": [">", 0],
            "due_date": ["<", nowdate()],
            "docstatus": 1  # submitted
        },
        fields=["name", "customer", "customer_name", "due_date", "posting_date", "outstanding_amount", "owner"]
    )

    for inv in overdue_invoices:
        try:
            invoice_doc = frappe.get_doc("Sales Invoice", inv.name)
            customer_email = frappe.db.get_value("Customer", inv.customer, "email_id")
            if customer_email:
                frappe.sendmail(
                    recipients=[customer_email],
                    subject=f"Reminder: Payment Overdue for Invoice {inv.name}",
                    template="Overdue Payment Reminder",
                    args={"doc": invoice_doc},
                    reference_doctype="Sales Invoice",
                    reference_name=inv.name,
                )
        except Exception as e:
            frappe.log_error(f"Error sending overdue reminder for Invoice {inv.name}: {e}")

3. Set Up Scheduler

Ensure your site scheduler is running:

bench --site your-site-name enable-scheduler

And supervisor is configured properly (for production).


:white_check_mark: Optional Improvements

  • Add a field reminder_sent in Sales Invoice to avoid duplicate emails.
  • Send only after N days overdue.
  • Add logs or Notification Log entries for transparency.

Let me know if you want to send SMS instead of email, or want a UI toggle to enable/disable reminders per customer.

2 Likes

If you want to send overdue payment email reminders in ERPNext without writing any code, you can achieve it using Email Alerts (Notifications). Here’s how you can set it up:


:white_check_mark: No-Code Setup for Overdue Payment Email Reminders

1. Create an Email Template

  1. Go to Email Template → Click New

  2. Fill in:

    • Name: Overdue Payment Reminder

    • Subject: Reminder: Payment Overdue for Invoice {{ doc.name }}

    • Message:

      Dear {{ doc.customer_name }},
      
      This is a friendly reminder that your payment for Invoice {{ doc.name }} is overdue.
      
      **Invoice Date**: {{ doc.posting_date }}  
      **Due Date**: {{ doc.due_date }}  
      **Outstanding Amount**: ₹{{ doc.outstanding_amount }}
      
      Please make the payment at your earliest convenience.
      
      Thank you,  
      Accounts Team
      
    • Save it.


2. Create a Notification

  1. Go to Notification (Search in Awesome Bar) → Click New

  2. Fill the following:

    Basic Info:

    • Document Type: Sales Invoice

    • Subject: Overdue Payment Reminder

    • Send Alert On: → Select Days After

      • Days After: due_date
      • No. of Days: 1 (or more)
    • Condition:

      doc.outstanding_amount > 0 and doc.docstatus == 1
      
    • Is Standard: Unchecked

    Recipients:

    • In Recipients table:

      • Recipient: Customer
      • Email by Document Field: customer_email (or use contact_email or create a custom field to store customer email)

    Message Template:

    • Attach Document Print: Optional
    • Email Template: Overdue Payment Reminder (select the one you created)
  3. Save the notification.


3. Ensure Emails Are Working

Make sure:

  • Outgoing Email is configured in Email Account.
  • Scheduler is running if you’re in a production/development server.

:white_check_mark: Done!

ERPNext will now automatically send overdue payment reminders without any coding required.

2 Likes