How to Automatically Send Email on Submission of Sales Invoice or Purchase Invoice?

Hi everyone,

I need help automating email notifications in Frappe. My requirement is as follows:

Sales Invoice (S.I): Whenever a Sales Invoice is submitted, a copy of the invoice should be automatically sent to the Customer via email.
Purchase Invoice (P.I):Similarly, when a Purchase Invoice is submitted, a copy of the invoice should be sent to the Supplier.

:white_check_mark: I want the email to include:

The Invoice PDF as an attachment.
A customized subject and message body.

I’m looking for the best approach — whether to use Server Scripts, Custom App Hooks, or if there is a built-in feature I can leverage. If anyone has implemented something similar or can guide me with a code example, I would greatly appreciate it!

Thanks in advance!

Hi @SaadKhan check this out
goto email notificatoin and create a new email notificatoin

here you can add message as per your requirments


go down here you can add the notification role vise or field vise and add the message you want

and at last you can check send attachments and set letter head but for this first you need to create a print format for this document or it will send the default print format
hope this helps

1 Like

but here how to fetch the email field which is on sales invoice. here

You can directly use doc in this message.
For more details, please refer to the documentation:
https://docs.frappe.io/erpnext/user/manual/en/notifications

@SaadKhan You can fetch the customer’s email automatically in the Sales Invoice by linking it from the Contact Doctype. Add the customer’s email in the Contact Doctype and set it as the primary email. When a customer is selected in the Sales Invoice, the email will be auto-filled in the contact_email field.

Additionally, as suggested by @Mubasher , you can use the Notification Doctype to trigger an email. Under the Recipient field, use the appropriate dynamic field to ensure emails are sent automatically.

Thank you This Help me