Send emails to all contacts in a deal

Send a templated email to all relevant contacts of a deal with one click from within the deal record in your CRM.

It is common for businesses to send emails to all contacts associated with a deal during the sales process. For example, they could send a deal confirmation email, an event invitation, or a payment request. A predefined email template can come in handy for such communication. However, if you take a cursory look at your CRM, sending emails from inside a deal record has two key constraints. First, it doesn't auto-open the editor with a predefined email template; second, it only includes the primary contact's email address as the recipient. This means your salespeople must insert a template and enter the email addresses of all the related contacts as recipients whenever they send an email. Would it be helpful if you sent such transactional emails to all the deal contacts with the click of a button? Fortunately, our low-code tools can make this possible.

Using functions, you can automatically send a templated email to all the contacts associated with a deal. To do this, create a custom button in the deals module that sends the email when clicked, then connect this button to the function. Read on to learn more.

Permissions and availability

  • Users with the Manage Extensibility permission can create connections and write custom functions.
  • Users with the Modules Customization permission can create custom buttons.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Create a Zoho OAuth connection with the required scopes for your Zoho CRM, as detailed in the "Create Connection" section below. Learn more
  • Create a custom button, as detailed in the "Create Button" section below. Learn more
  • Write a custom Deluge function to be linked with the button. Learn more
  • Test the workflow rule in a sandbox before deploying it in your production environment. Learn more

Create a connection

The first step is to create an OAuth connection in your Zoho CRM account.

  1. Go to Setup > Developer Space > Connections.
  2. Click Create Connection.
  3. Select Zoho OAuth under Default Services.
  4. Specify a Connection Name.
    You will enter this name in the code snippet below.
  5. Select the following Scopes to request access:
    • ZohoCRM.send_mail.all.CREATE
    • ZohoCRM.modules.ALL
  6. Click Create and Connect.
  7. Click Connect, then click Accept to confirm authorization of access for the scope requested by the client.

Create a button

The next step is to create a custom button linked to a function in the deals module.

  1. Navigate to Setup > Customization > Modules and Fields > Deals > Buttons > Create New Button.
  2. Provide a name for the button. For example: "Send Email".
    Add a description (optional).
  3. Choose the layouts where you want the button to be placed.
  4. Specify the button's placement as In Record and its position on the page as Details.
  5. Select the action to be performed as Writing Function.
  6. Provide a name and display name for the function, and click Create.
  7. On the Deluge Script Editor, do the following:
    1. Copy and paste the code provided below.
    2. Click Edit Arguments.
    3. Enter the name as id, select the value as Deals - Deal Id, then click Save.
    4. Save the function.
  8. Select the profiles who can view this custom button.
  9. Click Save.

The code

Code Copied
deal = zoho.crm.getRecordById("Deals", id);
conts = zoho.crm.getRelatedRecords("Contact_Roles", "Deals", id);
data = Map();
b_list = list();
to = Map();
cc_list = list();
c = Map();
a = Map();
a.put("email",zoho.loginuserid);
a.put("user_name",zoho.loginuser);
data.put("from",a);
b = Map();
b.put("email",email);
b_list.add(b);
for each d in conts
{
cont_email = zoho.crm.getRecordById("Contacts", d.getJson("id"));
b = Map();
b.put("user_name",cont_email.getJson("Full_Name"));
b.put("email",cont_email.getJson("Email"));
b_list.add(b);
}
data.put("to",b_list);
data.put("subject","Subject");
data.put("mail_format","html");
emp = Map();
emp.put("id","xxxxx");
data.put("template",emp);
f = list();
f.add(data);
final = Map();
final.put("data",f);
info final;
send = invokeurl
[
 url :"https://www.zohoapis.com/crm/v7/Deals/"+id+"/actions/send_mail"
 type :POST
 parameters:final.tostring()
 connection:"connectionname"
];
info send;
return "Email sent successfully";

Notes

  • Replace "xxxxx" with the ID of the email template for deals.
  • Replace "connectionname" with the name of the connection you specified when creating it (see the "Create a connection" section above).
  • As the API URLs differ for each data center, you should identify your account's data center and use the corresponding domain in the url. For example, for India, use https://www.zohoapis.in/crm.
  • Use the accurate API names for their corresponding fields in the code snippet. Learn more
  • The function will send emails to the deal's contact and to those in the Contact Roles related list.
  • The script above is an example of how to automatically send a templated email to all contacts related to a deal at the click of a button. You can use this code to send emails from any other module by changing the module, field names, and other parameters.

Tip

  • Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.

Test the solution

  1. Navigate to the Deals module.
  2. Open the deal record created for a contact that has users associated with it under Contact Roles in their related list.

    Note: The contact and the users assigned to the contact roles must have an email address.
  3. Click the custom button you've created in the steps above.
  4. Check whether the email was sent to all intended recipients as specified in the function.

Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.

More info

  • ModuleDeals
  • Trigger PointCustom Button
  • EditionEnterprise and above
  • ComplexityMedium
  • Implementation Time60 minutes

Features used in the solution

ConnectionCustom ButtonDeluge ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!