# Gmail

This guide explains how to enhance your chatbot by integrating Gmail for sending emails, making it a versatile tool for communication and automation.

{% hint style="warning" %}
The Gmail feature shouldn't be confused with the [Send mail Action](https://docs.chatlayer.ai/bot-answers/dialog-state/action-bot-dialog#mail-report-and-send-email) step, which allows you to send emails that are Chatlayer-branded. With the Gmail integration, you can send emails directly from your own Gmail account.
{% endhint %}

## Add Gmail Action to your flow

1. Within your chatbot's workflow, locate and add a new **Action** block.
2. Choose **Integrations** from the options available and then select the **Gmail** app.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FwRvyZXhLoTNn5UjfKfK7%2FScreenshot%202024-03-28%20at%2014.15.53.png?alt=media&#x26;token=3c1024c0-197e-4314-b80c-d6c73a3fa666" alt="" width="375"><figcaption><p>Select Gmail under Integrations</p></figcaption></figure>

3. You will be presented with an Action field. Select **Send Email** to proceed.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F6AKTxMCvOPvvS3CqCsnF%2FScreenshot%202024-03-28%20at%2014.17.37.png?alt=media&#x26;token=4be2aae9-8f79-4265-bdb5-0bb0bcc4d90c" alt="" width="375"><figcaption><p>Select Send Email</p></figcaption></figure>

## Configure your Gmail account

1. In the **Gmail account** section, click on **Connect new account** to connect your accoun&#x74;**.**&#x20;

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FPeRQKU0g21ErvEwZtO5F%2FScreenshot%202024-03-28%20at%2013.08.23.png?alt=media&#x26;token=e89af115-2902-414a-8a26-ba66a856e992" alt="" width="375"><figcaption><p>Click on Connect new account to connect your account.</p></figcaption></figure>

2. Follow the on-screen instructions to authorize your chatbot to access the Gmail account. This process may require you to log in to your Gmail account and grant specific permissions.

## Compose your Email

1. In the **Action** fields, locate the **To** input field to specify the recipient(s) of the email. There are 2 possibilities:
   * &#x20;If your bot has already collected the user's email address and saved it in a variable (e.g., `{userEmailAddress}`), you can use this variable directly.&#x20;
   * Alternatively, you can manually type the email addresses of the recipients, separating multiple addresses with commas.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FfNC1dT9kZ1DUYuOos8jq%2FScreenshot%202024-03-28%20at%2013.57.08.png?alt=media&#x26;token=cfed4b16-7645-40fd-8414-529bd7506309" alt="" width="375"><figcaption><p>Specify email recipients</p></figcaption></figure>

2. In the **Subject** field, personalize the email subject based on the interaction context. For instance, if you're sending a gym class booking confirmation, use the variable `{className}` to dynamically insert the class name. An example subject could be *🧘‍♂️Your* `{className}` *Class Booking Confirmation.*

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2FOTItmaheAfj6RKYBPbUb%2FScreenshot%202024-03-28%20at%2013.57.59.png?alt=media&#x26;token=29b6c9e7-ab3c-409d-a2c1-6937470f0d48" alt="" width="368"><figcaption><p>Email subject text field</p></figcaption></figure>

3. Compose the body of your email in the **Email content** field. Use variables to personalize the email content with information collected by the bot, such as booking details for a gym class.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F0NwvxQxgiEecH81lHR75%2FScreenshot%202024-03-28%20at%2014.03.23.png?alt=media&#x26;token=ecaeaaf2-c34a-4f0e-8732-87bd6761a5cb" alt="" width="364"><figcaption><p>Email content text field</p></figcaption></figure>

## Handling the response

1. Specify a **destination variable name** where the response from Gmail will be stored. This is useful for tracking the success or failure of the email sending operation.
2. Optionally, select a **block** to handle situations where the operation fails, allowing for graceful error handling within your chatbot flow. For instance, in this example, we used the **Error occurred** block.

<figure><img src="https://2786867680-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LLTwFwbOqJj4dDhg8Ju%2Fuploads%2F9VeVUELwBh2MFHqwybgJ%2FScreenshot%202024-03-28%20at%2014.05.17.png?alt=media&#x26;token=e4219d33-b710-43c6-8917-7ea14edb01a8" alt="" width="375"><figcaption><p>Specify destination variable and select block to handle on failure</p></figcaption></figure>

3. After completing the setup and configuration, ensure to click **Save** to apply your changes.

By following these detailed steps, you can empower your chatbot with the ability to send emails via Gmail, enhancing its utility and your users' experience.<br>
