> 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/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-add-email-recipients-from-related-lists.md).

# How To: Add Email Recipients from Related Lists

Pull related list email addresses into To, CC, or BCC recipients.

Use `addToEmail` when a template should populate recipients automatically from queried records.

### Problem

You want to automatically add email addresses from a related list as document recipients.

### Solution

**Add Contacts as primary recipients:**

```
<!--{{!
<lineitemsSOQL>
<class>none</class>
<soql>SELECT Email FROM Contact WHERE AccountId = '{{!Account.Id}}' AND Email != null</soql>
<column addToEmail="To">Email</column>
</lineitemsSOQL>
}}-->
```

**Add Account Team members as CC:**

```
<!--{{!
<lineitemsSOQL>
<class>none</class>
<soql>SELECT User.Email FROM AccountTeamMember WHERE AccountId = '{{!Account.Id}}'</soql>
<column addToEmail="CC">User.Email</column>
</lineitemsSOQL>
}}-->
```

**Add Created By users as BCC:**

```
<!--{{!
<lineitemsSOQL>
<class>none</class>
<soql>SELECT CreatedBy.Email FROM Opportunity WHERE AccountId = '{{!Account.Id}}'</soql>
<column addToEmail="BCC">CreatedBy.Email</column>
</lineitemsSOQL>
}}-->
```

### Important Notes

* You must also add `addToEmail` as an Apex parameter to your S-Docs button URL.
* Only non-null email addresses are included.
* `<class>none</class>` prevents the email list from rendering in the document.
* This works with any object that has email fields.

### Complete Example

**Button URL parameter:**

```
&addToEmail=true
```

**Template code:**

```
<!--{{!
<lineitemsSOQL>
<class>none</class>
<soql>SELECT Email FROM Contact WHERE AccountId = '{{!Account.Id}}' AND Email != null AND MailingList__c = true</soql>
<column addToEmail="To">Email</column>
</lineitemsSOQL>
}}-->
```

### Tips

* Filter aggressively so only intended recipients are added.
* Combine with other SOQL filters for tighter control.
* Test with a small group first.
* Do not forget the button parameter.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-add-email-recipients-from-related-lists.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
