Introduction

Before emailing an S-Docs document, you can choose an S-Docs HTML email template to automatically fill out the email body, subject line, and To/CC/BCC fields. This document will explain how to create S-Docs HTML email templates in the template editor. For a more in-depth explanation on how to create your first S-Docs template, click here.

Create The Email Template

To create an S-Docs email template, simply create a new S-Docs template and choose HTML as the Template Format.

Creating an S-Docs HTML email template

In the template editor, enter the contents of the email body. You can use merge fields, SOQL queries, custom HTML code, etc. as you would in any other template.

Designing a custom HTML email template in the S-Docs template editor

Configure Email Settings For The Template

To configure email settings for your template such as the subject line and the To/CC/BCC fields, navigate to the Email Settings tab in the template editor.

The email settings options appear as follows:

Note: If you use merge fields in this tab, make sure to use only one set of brackets instead of two. For example, use {!Contact.Email} instead of {{!Contact.Email}}.

[1] Email Subject: Set the email subject here. You can enter static text or merge fields.

[2] Email Subject Options:

  1. Lock Subject Line Field: Prevent the user from setting the subject line of the email
  2. Require Subject Line: Prevent the user from sending the email without inputting a subject line
  3. Email Lock Body: Prevent the user from editing the body of the email
Note: If you lock an email field and leave it blank in the template editor, the field will not appear on the S-Docs email page.

[3] Email Recipients: 

  1. Email SendTo, Email_cc, & Email_bcc: Set the email recipients here. You can enter static email addresses or use merge fields
  2. Set the default FROM address: Choose from a list of org-wide email addresses to set as the default "from" address. By default, this field is set to the user sending the email
  3. Restrict Email To The Following Domains: Enter a list of domains that users can send emails to. Users will not be able to send emails to any domains outside of the ones listed here if this field is populated. Specify domains as a comma-delimited list without @ symbols. For example: sdocs.com,trailhead.edu

[4] Email Recipient Settings:

  1. Lock SendTo Address: Prevent the user from adding recipients to the SendTo field. If the Email SendTo field is left blank and this option is checked, users will not be able to email the document. Click here for more information about restricting templates from being emailed
  2. Email Lock cc & Email Lock bcc: Prevent the user from adding CC or BCC recipients
  3. Email From: User can pick from address: Allow the user to select the "email from" address from a picklist of org-wide email addresses on the S-Docs email page
  4. Email From: Show only Org-Wide Addresses: This will restrict "email from" addresses to be only org-wide addresses (meaning that emails cannot be sent as the logged in user)
  5. Email FROM: Use User Signature if FROM address is 'Logged In User': Append the user's Salesforce email signature to the email body if the "email from" address is set to the logged in user

Once you have set your email fields, click Save. That's it! You can now use this email template to send pre-populated emails from S-Docs.

Generate The Email Template

To use your new email template when you're emailing S-Docs, simply select this template in addition to any other S-Doc you'd like to attach to the email.

Note: If you have specified a default email address, subject line, etc. in the Email Settings Tab when editing your HTML template, and another default email address, subject line, etc. in the Email Settings tab of another template (say a DOC or a PDF) that you are attaching to this email, S-Docs will ignore the email info in the non-HTML template(s) and only use the email info specified in the HTML email template.

Generate the docs by clicking Next Step, then click Email Selected Docs.

This opens up the S-Docs email page. As you can see below, S-Docs used the HTML email template to create a custom email to send to the specified contact, and attached the other document (the PDF) to the email. On this page, you can choose email recipients using the Contact Quick Pick or Contact/User Lookup field. Learn more about these features here. Alternatively, if you know the email addresses of the people you’d like to send the document(s) to, you can just type them into the To, CC, and BCC fields.

You can also type in a subject line, add additional attachments, and make edits to the email body.

That's all there is to it!

Email Failure Troubleshooting

By default, S-Docs links outbound emails to the contact record with a matching email address; Salesforce requires this linkage. If you try to send an email to an email address that is not listed under any Contact record in your org, S-Docs will attempt to link it to a single dummy contact record called "No Contact Record." This contact record is created automatically by the S-Docs package to handle this linkage, and is immediately deleted once the email is sent.

If your org has implemented validation rules that require additional contact fields to be completed, then the S-Docs package will not be able to create this contact record. In this case, there are two main options.

Option 1 (Recommended)

Create a before insert, before update Apex trigger on the Contact object that automatically changes the fields on the No Contact Record that S-Docs creates so that your validation rules are not triggered. For example, the trigger might look like this if your validation rules prevent the contact field "This_Cannot_Be_Null__c" from being null:

trigger ContactFirstName on Contact (before insert, before update) {
    for (Contact c : trigger.new) {
        if (c.LastName == 'No Contact Record') {
            c.This_Cannot_Be_Null__c = 'some non-null value';
        }
    }
}

With this option, S-Docs will be able to create and delete the No Contact Record, and the email will be sent and logged in Activity History on the base object record.

If you require test coverage for your No Contact trigger, you can use the following test class:

Class Name: NoContactTestClass

@isTest
private class NoContactTestClass {    @isTest
    public static void noContactTest() {
      Test.startTest();
        Contact testContact = new Contact();
        testContact.LastName = 'No Contact Record';
        insert testContact;
        Test.stopTest();
    }}

Option 2

Create the S-Docs No Contact Record manually with all of the fields filled in that are required by your validation rules. The fields that S-Docs requires should be filled in as follows:
First Name: Not Required. We recommend writing S-Docs to avoid confusion.
Last Name: No Contact Record
Email Address: this.email@is.invalid
You then need to add the following parameter to the end of your S-Docs button: &useExistingNoContactRecord=true
Note: This option is not recommended, as the email will not be logged in Activity History on the base object record.

Sandbox Deliverability

If you are testing S-Docs in a sandbox org and emails are not being delivered, you should check Setup > Email Administration > Deliverability, and check that "Access to Send Email" is set to "All email." By default, Salesforce turns off outbound email access when a sandbox is created to reduce the risk of inadvertently sending emails to contacts during development and testing. Be aware that this change effects the entire sandbox and not just S-Docs.