Write a Client Script to Automatically Send Email Using Email Templates After Document Creation

Could you please provide guidance on how to write a client script that sends an email using email templates after a new document is inserted in the doctype?

@Prathyusha ,
I think you can use Notification Doctype. This doctype will handle to send notification for new documents.

i want to send emails to the user based on status field value,based on the its value email template is changed thats why i am trying to use Email Template doctype.

@Prathyusha write more than one notification and write a condition on each one depending on the status

@Prathyusha

There is also an option for that. “Send Alert On” and Value Changed.
Try to utilize that. and add multiple documents for status

yeah
the notification method is the best possible way
if you need another way you can write code in hooks.it is also possible way to do this task

I am trying Notifications also but not getting mails.But not working.

My doctor where i am trying to apply this feature

@Prathyusha Try to check in email Queue.

Create an Email Template in your system, including placeholders for dynamic data.
Write a Server Script to trigger the after_insert event, fetch the email template, format the message, and send the email using the system’s email service.

it’s pretty straightforward if you setting up client script automatically send an email creating a document

First, you’ll need to use a document-created event to trigger the script, and then, you can fetch the email template you want to use with something like the EmailTemplate.load method. Once the template is loaded, email send to send it off automatically.

I’d check out some examples on https://www.maestrolabs.com/blog-detail/email-writing-tools to get a feel for how others set it up and tweak it to fit your needs. It might also be helpful to ensure your script runs after the document is entirely created, so a delay or confirmation check could be a good idea to avoid timing issues.