# Sendgrid

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FcPgTr3BAR66o06K1QNcp%2Fimage.png?alt=media&#x26;token=71ee3a19-f487-4e1d-beab-978b79d8a9af" alt="" width="188"><figcaption></figcaption></figure></div>

The Sendgrid service allows you to send automated emails from your app using the [Twilio Sendgrid API](https://sendgrid.com/).

***

## Profile Settings

{% hint style="success" %}
NOTE: All profile settings are encrypted and stored in Zingy's cloud infrastructure.
{% endhint %}

### API Key

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FifLqhwlHn3Ae4v28gcO2%2Fimage.png?alt=media&#x26;token=9956886b-654e-4b39-ba51-75afda0cf351" alt="" width="375"><figcaption></figcaption></figure></div>

Enter your [Sendgrid API Key here](https://docs.sendgrid.com/ui/account-and-settings/api-keys).

***

## Connection Settings

{% hint style="success" %}
NOTE: All connection settings are encrypted and stored in Zingy's cloud infrastructure.
{% endhint %}

### From Address

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FvgTZFWpai76lW0HaKPmv%2Fimage.png?alt=media&#x26;token=1fbcb602-f60f-4535-a52d-32ef43b968ef" alt="" width="375"><figcaption></figcaption></figure></div>

Enter the from address to use when sending the email using this connection.

***

## Operations/Commands

The [Execute Connection Command](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/execute-connection-command) block is available in both [Page Flow](https://docs.zingy.ai/app-editor/page-flow) and [Cloud Flow](https://docs.zingy.ai/app-editor/cloud-flow). Using this block you can add logic to trigger the operations/commands supported by the Sendgrid service.

{% hint style="success" %}
For security purposes, all operations/commands offered by the Sendgrid service are only available in [Cloud Flow](https://docs.zingy.ai/app-editor/cloud-flow) and cannot be used in [Page Flow](https://docs.zingy.ai/app-editor/page-flow).
{% endhint %}

### Send Email (Plain Text)

Use this command to send a plain-text email using the Sendgrid service.

#### Input Data

When invoking this operation, an object with the following properties is required:

<table><thead><tr><th width="149">Property</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>toAddr</td><td><a href="../../page-flow/references/value-types">text</a> or <a href="../../page-flow/references/value-types">list</a> </td><td>One or more recipient email addresses. For multiple addresses use a <a href="../../page-flow/references/value-types">list</a>.</td></tr><tr><td>ccAddr</td><td><a href="../../page-flow/references/value-types">text</a> or <a href="../../page-flow/references/value-types">list</a></td><td>Optional. One or more CC email addresses. For multiple addresses use a <a href="../../page-flow/references/value-types">list</a>.</td></tr><tr><td>bccAddr</td><td><a href="../../page-flow/references/value-types">text</a> or <a href="../../page-flow/references/value-types">list</a></td><td>Optional. One or more BCC email addresses. For multiple addresses use a <a href="../../page-flow/references/value-types">list</a>.</td></tr><tr><td>subject</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The subject for the email.</td></tr><tr><td>msg</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The email's message or body.</td></tr><tr><td>customProps</td><td><a href="../../page-flow/references/value-types">object</a></td><td>Optional. For advanced users, this specifies an object with properties based on parameters used by the <a href="https://github.com/sendgrid/sendgrid-nodejs/tree/main/packages/mail">Sendgrid API</a>.</td></tr></tbody></table>

#### Output

The Send Email (Plain Text) command does not provide any output beyond the Success/Fail status.

### Send Email (HTML)

Use this command to send an email in HTML format using the Sendgrid service.

#### Input Data

When invoking this operation, an object with the following properties is required:

<table><thead><tr><th width="149">Property</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>toAddr</td><td><a href="../../page-flow/references/value-types">text</a> or <a href="../../page-flow/references/value-types">list</a> </td><td>One or more recipient email addresses. For multiple addresses use a <a href="../../page-flow/references/value-types">list</a>.</td></tr><tr><td>ccAddr</td><td><a href="../../page-flow/references/value-types">text</a> or <a href="../../page-flow/references/value-types">list</a></td><td>Optional. One or more CC email addresses. For multiple addresses use a <a href="../../page-flow/references/value-types">list</a>.</td></tr><tr><td>bccAddr</td><td><a href="../../page-flow/references/value-types">text</a> or <a href="../../page-flow/references/value-types">list</a></td><td>Optional. One or more BCC email addresses. For multiple addresses use a <a href="../../page-flow/references/value-types">list</a>.</td></tr><tr><td>subject</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The subject for the email.</td></tr><tr><td>msg</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The email's message or body in HTML format.</td></tr><tr><td>msgText</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The email's message or body in text format. Used for cases where the recipient's email client is unable to show the HTML formatted message.</td></tr><tr><td>customProps</td><td><a href="../../page-flow/references/value-types">object</a></td><td>Optional. For advanced users, this specifies an object with properties based on parameters used by the <a href="https://github.com/sendgrid/sendgrid-nodejs/tree/main/packages/mail">Sendgrid API</a>.</td></tr></tbody></table>

#### Output

The Send Email (HTML) command does not provide any output beyond the Success/Fail status.

### Send Email (Template)

Use this command to send an email using a pre-defined template in your Sendgrid account.

#### Input Data

When invoking this operation, an object with the following properties is required:

<table><thead><tr><th width="211">Property</th><th width="90">Type</th><th>Description</th></tr></thead><tbody><tr><td>toAddr</td><td><a href="../../page-flow/references/value-types">text</a> or <a href="../../page-flow/references/value-types">list</a> </td><td>One or more recipient email addresses. For multiple addresses use a <a href="../../page-flow/references/value-types">list</a>.</td></tr><tr><td>ccAddr</td><td><a href="../../page-flow/references/value-types">text</a> or <a href="../../page-flow/references/value-types">list</a></td><td>Optional. One or more CC email addresses. For multiple addresses use a <a href="../../page-flow/references/value-types">list</a>.</td></tr><tr><td>bccAddr</td><td><a href="../../page-flow/references/value-types">text</a> or <a href="../../page-flow/references/value-types">list</a></td><td>Optional. One or more BCC email addresses. For multiple addresses use a <a href="../../page-flow/references/value-types">list</a>.</td></tr><tr><td>subject</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The subject for the email.</td></tr><tr><td>templateId</td><td><a href="../../page-flow/references/value-types">text</a></td><td>The identifier of the Sendgrid template.</td></tr><tr><td>substitutions</td><td><a href="../../page-flow/references/value-types">object</a></td><td>Object containing dynamic dynamic substitutions.</td></tr><tr><td>substitutionWrappers</td><td><a href="../../page-flow/references/value-types">list</a></td><td>Optional. Defaults to <em>{{</em> and <em>}}</em>. A list containing the starting and ending wrappers for identifying substitution properties.</td></tr><tr><td>customProps</td><td><a href="../../page-flow/references/value-types">object</a></td><td>Optional. For advanced users, this specifies an object with properties based on parameters used by the <a href="https://github.com/sendgrid/sendgrid-nodejs/tree/main/packages/mail">Sendgrid API</a>.</td></tr></tbody></table>

#### Output

The Send Email (Template) command does not provide any output beyond the Success/Fail status.

***

## Advanced Functionality

In your app's Cloud Flow Web Hooks and Background Tasks, the [Custom Code](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/custom-code) block can be used to access and implement advanced functionality related to the Sendgrid email service.

To access the  client initialized with credentials saved on this Sendgrid service connection, see the following example:

```javascript
// To use a sendgrid client initialized with credentials
// provided in a Sendgrid connection
const sgMail = zingyConn.sendgrid(connectionName);
```

You may also initialize a separate Sendgrid client, by specifying account credentials directly:

```javascript
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(apiKey);
```

After the `sgMail` object is initialized, you can use it to call into the [Sendgrid library](https://www.npmjs.com/package/@sendgrid/mail).

If you need to utilize Sendgrid API beyond simply sending emails, please see [@sendgrid/client](https://docs.zingy.ai/cloud-flow/sdk-library-integration#sendgrid-client) .
