# Create Your First Email Template

## What You'll Learn

* Create an HTML email template for `Opportunity`
* Add merge fields to the email body
* Configure default subject, recipient, and sender settings
* Test the template with a real Salesforce record
* Troubleshoot blank recipients and raw merge field output

## What You'll Build

In this tutorial, you will build a reusable quote delivery email template for `Opportunity`.

By the end, you will have:

* An HTML template that works as the email body
* A personalized message with `Opportunity` and `Account` merge fields
* A default subject and recipient value
* A tested email flow ready for document delivery

**Estimated time:** 15 minutes

## Prerequisites

Before you start, make sure you have:

* Access to **S-Docs Templates** in Salesforce
* Permission to create and edit S-Docs templates
* One test `Opportunity` with an `Account` and a valid email field
* Basic familiarity with merge fields such as `{{!Opportunity.Name}}`

If you plan to use an org-wide sender address, make sure it already exists in Salesforce.

{% stepper %}
{% step %}

### Step 1: Create the email template record

Start by creating the template record that will hold the email body and email settings.

1. Open the App Launcher.
2. Search for `S-Docs`.
3. Open **S-Docs Templates**.
4. Click **New**.
5. Set **Template Name** to a clear value, such as `Opportunity Quote Email`.
6. Set **Related To Type** to `Opportunity`.
7. Set **Template Format** to `HTML`.
8. Click **Save**.

What you just did:

* Created a template record for email content
* Tied the template to `Opportunity`
* Chose the format required for email body templates
  {% endstep %}

{% step %}

### Step 2: Open the template editor

Now open the editor where you will build the body and set email defaults.

1. Open the new template record.
2. Click **Template Editor**.

You are now in the editor for the new HTML template.
{% endstep %}

{% step %}

### Step 3: Build the email body

Start with a short message that uses a few merge fields.

Add a body like this:

{% code title="Email body" %}

```html
Hello {{!Opportunity.Account.Name}},
Thank you for reviewing {{!Opportunity.Name}}.
Please find your quote attached.
If you have questions, reply to this email and we will help.
```

{% endcode %}

You can type the content directly in the editor, or insert fields from the field picker and build the message around them.

What you just did:

* Added the visible email message
* Personalized the body with record data
* Used double-brace merge fields for template body content
  {% endstep %}

{% step %}

### Step 4: Set the default subject

Use a subject that tells the recipient exactly what the email contains.

1. Open **Email Settings**.
2. In **Email Subject Settings**, find **Subject**.
3. Enter this value:

{% code title="Email subject" %}

```
Quote for {!Opportunity.Name} - {!Opportunity.Account.Name}
```

{% endcode %}

4. Leave **Lock Subject** unchecked.

Example output: `Quote for Renewal - Acme Corporation`

{% hint style="info" %}
Use single-brace merge fields like `{!Opportunity.Name}` in settings tabs. Use double-brace merge fields like `{{!Opportunity.Name}}` in the template body.
{% endhint %}

What you just did:

* Added a reusable subject pattern
* Pulled record values into the subject
* Kept the subject editable for users
  {% endstep %}

{% step %}

### Step 5: Set the default recipient

Now define who receives the email by default.

1. Stay in **Email Settings**.
2. In **Email Recipient Settings**, find **To**.
3. Enter the merge field for your email source.

Example:

{% code title="To address" %}

```
{!Opportunity.Account.BillingEmail}
```

{% endcode %}

{% hint style="info" %}
If the merge field does not result into a value, feel free to use your personal email address for testing.&#x20;
{% endhint %}

4. Leave **Lock To** unchecked.

Use the email field that fits your process best.

If your org stores email on another related record, use that field instead.

What you just did:

* Set a default recipient for the template
* Pulled the value from the source record
* Left the field open for user review and edits
  {% endstep %}

{% step %}

### Step 6: Set sender behavior and basic guardrails

Choose who the email appears to come from and apply any limits you need.

1. In **Email Sender Settings**, find **From**.
2. Select one of these options:
   * `Logged in user`
   * Your org-wide email address
     {% endstep %}

{% step %}

### Step 7: Save and test the template

Test the base version before you add more variations.

1. Click **Save**.
2. Open a test `Opportunity`.
3. Generate a document with the template.
4. Open the email action.
5. Verify these results:
   * **Subject** is prefilled
   * **To** is prefilled when the source field has data
   * The body shows merged record values
   * **From** matches your selected sender option

Send one test email when everything looks correct.

What you just did:

* Confirmed the template works with real record data
* Verified the body, subject, and recipient behavior
* Finished one working email template before adding refinements
  {% endstep %}
  {% endstepper %}

## Common Issues and Solutions

<details>

<summary>The subject shows raw merge field text</summary>

Check these items:

* Use single braces in **Email Settings**, such as `{!Opportunity.Name}`
* Do not use double braces in settings tabs
* Save the template and generate a fresh test

</details>

<details>

<summary>The recipient field is blank</summary>

Check these items:

* Confirm the source email field contains data on the test record
* Confirm the field path matches the record relationship you used
* Leave **To** unlocked if users may need to type the address manually

</details>

<details>

<summary>The email body does not personalize correctly</summary>

Check these items:

* Use double braces in the body, such as `{{!Opportunity.Name}}`
* Confirm the field path is valid for the template's **Related To Type**
* Regenerate the email after each body change

</details>

<details>

<summary>The sender option I want is not available</summary>

Check these items:

* Confirm the org-wide email address already exists in Salesforce
* Confirm your user can access that sender option
* Test with `Logged in user` first if you need to isolate the issue

</details>

<details>

<summary>The template does not appear in the email workflow</summary>

Check these items:

* Confirm the template uses the correct **Related To Type**
* Confirm the template is available for the object you are testing
* Generate from a record that matches the template object

</details>

## What You've Learned

✅ Created an HTML email template for `Opportunity`\
✅ Added merge fields to the email body\
✅ Configured default subject, recipient, and sender settings\
✅ Tested the template with a real Salesforce record\
✅ Learned the most common fixes for email template issues

## Next Steps

* Use [Configure Template Settings: Email](/quick-start/template-building/customize-template-settings-email.md) to go deeper on sender controls, domain restrictions, and locked fields.
* Use [Generate and Email Your Document](/quick-start/getting-started/generate-and-email-your-document.md) to test the full end-user workflow.
* Use [Get Started with Merge Fields](/quick-start/template-building/how-to-auto-fill-customer-data-into-templates.md) if you want more field placement practice.

## Practice Exercise

Build a second email template for `Opportunity` that includes:

1. A subject with `Opportunity.Name`
2. A recipient pulled from a related email field
3. A short body with at least two merge fields
4. One test email sent from a real record

Bonus challenges:

* Switch the sender to an org-wide email address
* Add a domain restriction
* Lock the body after the base version works


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sdocs.com/quick-start/template-building/create-your-first-email-template.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
