# 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="/files/NEV9Uj4bMljLft14FKlz" 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="/files/ol9tV4uWMSIAtv0Kufyn" 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="/files/pu2QyJz3jXmJDNRYoEEo" 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="/files/RzeuTN0n7nuPbYaF3OKk" 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="/files/b5rTL9JYRQyz1WmVVbyj" 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="/files/PRV7AuEt5SOaOo1yYOoV" 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="/files/M7CZHAlczWNt0sGSJ5BS" 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>


---

# 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://docs.chatlayer.ai/integrateandcode/app-integrations/gmail.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.
