-
Notifications
You must be signed in to change notification settings - Fork 16
How to send your first email
This page describes step by step how to create and send your first custom email. Basically there are just 2 simple things to do:
1. Create a new custom template
2. Send an email using your new custom template
The next documentation is based on the solution sample DXTools Custom Emails Sample, which can be found in the Releases section.
Create a new Global Email Template. Out of the box, this template is not linked to any CRM entity, so that initially you can only used users dynamics attributes.
However, we are going to use a small trick to add dynamics attributes from our custom entity:
{attribute_logical_name}
Exactly, basically we are going to mark the logical attribute name with curly brackets. Let's have a look at this example:
In this example, we are assuming the custom entity Payment (dxtools_payment) will be our main entity. This way, {dxtools_paymentreference} is an attribute of the same that will be replaced dynamically based on the payment record given as an argument later on.
As part of the template, it is a good practice to attach the files you will send with your emails later on.
You have a couple of options to send your custom email, choose the one that fits better in your development:
The solution provides the custom workflow activity "Create Custom Email" which can be used from any CRM process (Workflow, Action, Dialog). See "New Payment Received" workflow in the sample solution.
Create Custom Email workflow activity parameters:
- Email Template Name: Name of the CRM email template to be used
- Sender Email Address: Email address of the user or queue which is sending the email (From)
- To Recipient Record URL: Record URL of the CRM record which is going to receive the email. It must be an CRM emailable entity.
- Email Regarding Record URL: Record URL of the CRM record which is going to be set as the regarding object of the email. It must be an entity suitable for activities.
- Record Context URL: Record URL of the CRM record which is going to be used to populate the values of the dynamics attributes of our custom template. This is considered the main entity type.
- Attachments: file names separated by comma. They must be template attachments in CRM. Notice the benefit of this solution is that you could use attachments from different templates in the same email.
- Allow Duplicate Attachments: Two or more different files with the same name could be in different templates. If you want to attach all of them, set this flag to True, otherwise set it to False. Using the second option, an exception will be thrown indicating the duplicate file and its templates. This can be useful to control unique version of attachments across different templates.
- Only Use Attachments in Template: Two or more different files could be in different templates with the same file name. In this case, you may just want to use the one attached in your corresponding template,
The next action create and send a custom email using the custom workflow activity previously described. Its arguments are basically the same as the "Create Custom Email" workflow activity, with the benefit that it allows multiple recipients (EntityCollection):
Because it is an action, it can be triggered from different context using the CRM SDK Web Services (e.g. JavaScript, plugins, custom applications, etc). In the source code, you can find the corresponding request type which has been generated using crmsvcutil.exe.
Dynamics Custom Emails - A Dynamics 365 (CRM) utility