function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prasanya KPrasanya K 

Write a trigger on the Contact object that, when a new email is inserted, sends an email to the contact's email address using a specified template. .

SwethaSwetha (Salesforce Developers) 
HI Prasanya,

First, create an email template: Go to Setup > Classic Email Templates > New Template. Select Visualforce option for 'type of template'. Create a new Visualforce email template with the desired content and save it.

Example code
trigger SendEmailOnNewEmail on EmailMessage (after insert) {
    // Collect a set of contact IDs from the inserted EmailMessage records
    Set<Id> contactIds = new Set<Id>();
    for (EmailMessage email : Trigger.new) {
        if (email.RelatedToId != null && email.RelatedToId.getSObjectType() == Contact.SObjectType) {
            contactIds.add(email.RelatedToId);
        }
    }
    
    // Query the contacts with their email addresses
    Map<Id, Contact> contactsWithEmails = new Map<Id, Contact>(
        [SELECT Id, Email FROM Contact WHERE Id IN :contactIds]
    );
    
    // Iterate through the inserted email records and send emails to contacts
    List<Messaging.SingleEmailMessage> emailMessages = new List<Messaging.SingleEmailMessage>();
    for (EmailMessage email : Trigger.new) {
        if (email.RelatedToId != null && contactsWithEmails.containsKey(email.RelatedToId)) {
            Contact contact = contactsWithEmails.get(email.RelatedToId);
            
            Messaging.SingleEmailMessage emailMessage = new Messaging.SingleEmailMessage();
            emailMessage.setTargetObjectId(contact.Id);
            emailMessage.setTemplateId('your_email_template_id_here'); // Specify the Email Template ID
            emailMessage.saveAsActivity = false;
            emailMessages.add(emailMessage);
        }
    }
    
    // Send the email messages
    Messaging.sendEmail(emailMessages);
}

Related:
https://developer.salesforce.com/forums/?id=906F0000000AUEgIAO
https://salesforce.stackexchange.com/questions/31477/send-an-email-template-from-trigger-on-quote-item
https://salesforceforfresher.wordpress.com/2021/07/08/sending-email-from-apex-trigger/

If this information helps, please mark the answer as best. Thank you
Prasanya KPrasanya K
thank you swetha
Prasanya KPrasanya K
it was helpful