> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/quick-start/document-generation/getting-started-automate-emails.md).

# Getting Started: Automate Emails

## What You'll Learn

* Extend a Screen Flow to email a generated S-Docs file
* Add the S-Docs **Send Email** action after document generation
* Pass the generated `SDoc ID` into the email action as an attachment
* Reuse an S-Docs email template for the message body
* Test the full generate-and-email flow from a real record

## What You'll Build

In this tutorial, you will update the `Opportunity` flow from [Generate Documents Using Flows](/quick-start/document-generation/getting-started-automate-document-generation.md).

By the end, you will have:

* One Screen Flow that generates a document
* One S-Docs email action after generation
* One outbound email that uses an S-Docs email template
* One generated PDF attached to the sent email

**Estimated time:** 10 minutes

## Prerequisites

Before you start, make sure you have:

* Complete [Create Your First Email Template](/quick-start/template-building/create-your-first-email-template.md)
* Complete [Getting Started: Automate Document Generation](/quick-start/document-generation/getting-started-automate-document-generation.md)

{% hint style="info" %}
The email action needs a valid recipient source. Use your S-Docs email template defaults, or map a recipient value in the flow action.
{% endhint %}

{% stepper %}
{% step %}

### Step 1: Open the existing flow

Start with the flow you built for document generation.

1. Go to **Setup**.
2. Open **Flows**.
3. Open your existing flow, such as `Generate Opportunity PDF`.

You are now back in the flow that already generates the document.
{% endstep %}

{% step %}

### Step 2: Add the Send Email action

{% hint style="warning" %}
Ensure you are choosing the correct Send Email action. You will see the S-Docs namespace listed in the invocable action.
{% endhint %}

Insert the email step after document generation.

1. Click the **+** between **Generate Document** and **Document Created**.
2. Choose **Action**.
3. Search for `Send Email`.
4. Select the S-Docs send email action.
5. Set **Label** to `Send Email`.
6. Set **API Name** to `Send_Email`.

What you just did:

* Added the second S-Docs action to the flow
* Placed email sending after the file is created
  {% endstep %}

{% step %}

### Step 3: Configure the core email inputs

Map the action to the same record, template, and generated file.

In **Set Input Values**:

1. Set **Base Record ID** to `{!recordId}`.
2. Enter the exact value for **S-Docs Email Template Name or ID**.
3. Set **Attachments** to the `SDoc ID` output from **Generate Document**.
4. Click **Done**.

Use the exact S-Docs email template name or record ID.

What you just did:

* Connected the email action to the current `Opportunity`
* Told the action which S-Docs email template to use
* Attached the file created by the previous step
  {% endstep %}

{% step %}

### Step 4: Add recipient overrides only when needed

Your email template may already control recipients, subject, or body.

Only map extra values in the flow when you need to override that behavior.

Common optional inputs include:

* **Recipient Email Address** when the template does not set a default recipient
* **CC** or **BCC** when your process requires extra recipients
* **Subject Line** when the flow must override the template default

Keep the first version simple.

Test the base flow before you add overrides.
{% endstep %}

{% step %}

### Step 5: Update the confirmation screen

Make the final screen match the new workflow.

1. Open the **Document Created** screen.
2. Update the **Display Text** message.
3. Use a short message such as:

{% code title="Confirmation message" %}

```
Document generated and emailed successfully.
Check your inbox and the record files for the result.
```

{% endcode %}

4. Click **Done**.

What you just did:

* Updated the user-facing result message
* Confirmed the flow now handles generation and email
  {% endstep %}

{% step %}

### Step 6: Save and activate the new flow version

Make the updated flow available on the record page.

1. Click **Save**.
2. Save the flow as a new version.
3. Click **Activate**.

Your existing record-page flow action can now run the updated version.
{% endstep %}

{% step %}

### Step 7: Test the full flow from an Opportunity record

Run the flow from a real record.

1. Open a test `Opportunity`.
2. Launch the flow from the record page.
3. Let the flow complete.
4. Verify the generated file appears on the record.
5. Verify the email arrives.
6. Open the email and confirm the generated PDF is attached.

Check these results:

* The flow completes without an error
* The correct email template is used
* The generated file is linked to the same `Opportunity`
* The email includes the generated document as an attachment
  {% endstep %}
  {% endstepper %}

## Common Issues and Solutions

<details>

<summary>I cannot find the Send Email action</summary>

Check these items:

* S-Docs is installed in the org
* You added an **Action**, not another element type
* You searched for `Send Email` in the action picker
* Your user can access S-Docs Apex actions

</details>

<details>

<summary>The email sends, but the document is not attached</summary>

Check these items:

* **Attachments** is mapped to the `SDoc ID` output from **Generate Document**
* The generate step runs before the email step
* The document was created successfully during the same flow run

</details>

<details>

<summary>The flow finishes, but no email arrives</summary>

Check these items:

* The email template is active
* The flow provides a valid recipient
* The recipient email address is real and accessible
* Your org allows outbound email from the selected sender

</details>

<details>

<summary>The wrong email content appears</summary>

Check these items:

* The **S-Docs Email Template Name or ID** matches the intended template
* The template contains the subject and body you expect
* The flow is not overriding the subject or recipients unexpectedly

</details>

<details>

<summary>The updated flow does not run from the record page</summary>

Check these items:

* The newest flow version is **Active**
* The existing flow action still points to this flow
* The record page or page layout was saved after earlier action setup

</details>

## What You've Learned

✅ Extended a Screen Flow to email a generated S-Docs file\
✅ Added the S-Docs **Send Email** action after document generation\
✅ Passed the generated `SDoc ID` into the email action\
✅ Reused an S-Docs email template in the flow\
✅ Tested the full generate-and-email workflow from a live record

## Next Steps

* Use [Configure Template Settings: Email](/quick-start/template-building/customize-template-settings-email.md) to set default recipients, subject, and sender behavior.
* Use [Generate Documents Using Flows](/quick-start/document-generation/getting-started-automate-document-generation.md) if you need to rebuild the base flow first.
* Use [Generate and Email Your Document](/quick-start/getting-started/generate-and-email-your-document.md) to review the end-user workflow on a record page.

## Practice Exercise

Extend the same flow to send a second email scenario.

1. Copy the flow.
2. Change the email template input to a different S-Docs email template.
3. Activate the copied flow.
4. Launch it from a test record.
5. Confirm the second email uses the new message content and still includes the generated PDF.

Bonus challenges:

* Override the recipient in the flow instead of the template.
* Add a custom subject for one flow variation.
* Repeat the same pattern for an `Account` flow.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://help.sdocs.com/quick-start/document-generation/getting-started-automate-emails.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
