Tip: Using SendEmailFromTemplateRequest to directly send an email using the Email Template

By | June 9, 2017

Earlier when we had an Email Template created for any entity, we used to follow the below four steps to send an email using Template:

  1. Retrieve the Email Template and get the Template Id
  2. Instantiate the template using InstantiateTemplate request and get the Response
  3. Create the Email in CRM using IOrganizationService object or OrganizationServiceContext object
  4. Execute Send Email Request to Send the Email

But recently while working with sending emails, we came across “SendEmailFromTemplateRequest” request which can be used to directly send emails using email templates by following the below steps:

  1. Retrieve the Email Template and get the Template Id
  2. Create an Email object in the code, don’t create in CRM using any service
  3. Simply execute SendEmailFromTemplateRequest request passing the parameters required

 Note: This approach can be used if you don’t want to edit the Email body or subject of an email using the Template.

Below is the code snippet in C# which you can use for reference:

 Note: SetEmailProperties() method returns the Email object with all the required attributes set i.e. as shown here.

Hope this helps and saves unnecessary step and request to CRM!

Export Dynamics 365 Reports to PDF or Word or Excel Format

Leave a Reply

Your email address will not be published. Required fields are marked *