# Email Trigger V2

**Email Trigger V2** retrieves data from an email inbox and delivers it to the pipeline.

{% hint style="info" %}
This trigger supports **IMAP protocol only**.
{% endhint %}

## **Parameters**

Take a look at the configuration parameters for the trigger. Parameters supported by [Double Braces expressions](https://docs.digibee.com/documentation/connectors-and-triggers/double-braces/overview) are marked with `(DB)`.

<table data-full-width="true"><thead><tr><th>Parameter</th><th>Description</th><th>Default value</th><th>Data type</th></tr></thead><tbody><tr><td><strong>Account</strong></td><td>Defines the <a href="https://app.gitbook.com/s/jvO5S91EQURCEhbZOuuZ/platform-administration/settings/accounts#accounts-type">account type</a> used by the trigger. Supported types: <strong>Basic</strong>, <strong>OAuth 2</strong>, and <strong>Azure Key</strong>.</td><td>N/A</td><td>String</td></tr><tr><td><strong>E-mail</strong></td><td>The email address to be accessed. If the account type is <strong>OAuth 2</strong>, only Google-hosted email addresses are supported. For Microsoft email addresses, use the <strong>Azure Key</strong> account type instead.</td><td>N/A</td><td>String</td></tr><tr><td><strong>Operation</strong></td><td>Specifies the action to be performed by the trigger. Options: <strong>Mark as Read</strong>, <strong>Move to Another Folder</strong>, and <strong>Delete</strong>. See details in the <strong>Operations</strong> section.</td><td>Mark as Read</td><td>String</td></tr><tr><td><strong>Hostname</strong></td><td>IMAP server hostname (for example, <code>imap.uol.com</code>).</td><td>imap.gmail.com</td><td>String</td></tr><tr><td><strong>Port</strong></td><td>Port number for the IMAP connection.</td><td>993</td><td>Integer</td></tr><tr><td><strong>Email Folder</strong></td><td>Name of the folder/inbox that the trigger will read (for example, <code>inbox</code>). This folder must not contain more than 100 messages (read or unread).</td><td>inbox</td><td>String</td></tr><tr><td><strong>Destination Email Folder</strong></td><td>Defines the folder where messages should be moved. This field is displayed only when <strong>Move to Another Folder</strong> is selected in the <strong>Operation</strong> parameter.</td><td>N/A</td><td>String</td></tr><tr><td><strong>Maximum Timeout</strong></td><td>Maximum processing time (in milliseconds) before the pipeline returns a response. Limit: <code>900000</code>.</td><td>30000</td><td>Integer</td></tr><tr><td><strong>Allow Redelivery Of Messages</strong></td><td>If enabled, allows messages to be redelivered if the Pipeline Engine fails.</td><td>False</td><td>Boolean</td></tr><tr><td><strong>Documentation</strong></td><td>Section for documenting any necessary information about the connector configuration and business rules.</td><td>N/A</td><td>String</td></tr></tbody></table>

## **Operations**

* **Mark as Read:** Marks the message as read after processing.
* **Move to Another Folder:** Moves the processed message to a specified folder. The **Destination Email Folder** field is required for this option.
* **Delete:** Deletes the message after processing.

## **Attachments**

If the received email contains attachments, they will be downloaded and stored in the pipeline's execution directory. The attachment names will be listed in the `attachments` property as an array of strings.

If two attachments have the same name, a unique identifier is added to differentiate them

**Example**

If an email contains two attachments named `file.csv`, the `attachments` property will be:

```json
{
    "attachments": ["file.csv", "0072e485-8ba2-4f79-bba5-8068e37ee792_file.csv"]
}
```

The identifier varies with each execution.

{% hint style="info" %}
When using Gmail as the IMAP server, you must enable access for less secure apps. Refer to [Google's external documentation](https://support.google.com/accounts/answer/6010255?hl=en) for details.
{% endhint %}

## **Usage example**

Follow the steps below to configure and use the trigger:

1. Open the trigger settings and select the **email-v2** type.
2. Fill in the configuration fields as needed. For this example, choose **Mark as Read** in the **Operation** field.
3. Click **Confirm**.
4. Continue [building the pipeline](https://app.gitbook.com/s/jvO5S91EQURCEhbZOuuZ/development-cycle/build-overview#how-to-create-a-pipeline).
5. Deploy the pipeline. Learn [step-by-step](https://app.gitbook.com/s/jvO5S91EQURCEhbZOuuZ/development-cycle/overview/deployment/deployments).

Once triggered, the pipeline will receive a payload similar to this:

```json
{
  "textMessage": "",
  "htmlMessage": "Hello, Peter\r\nI still haven’t received the report for this month. Could you send it by the end of the day?",
  "attachments": [
    "attachment_fileName1",
    "attachment_fileName2",
    "attachment_fileName3"
  ],
  "subject": "Monthly report",
  "from": [
    "Renato Peixe Junior <renato.peixe@gmail.com>"
  ],
  "to": [
    "peter.gomes@gmail.com"
  ],
  "cc": [],
  "bcc": [],
  "replyTo": [
    "Renato Peixe Junior <renato.peixe@gmail.com>"
  ],
  "sentDate": "2020-02-10T17:54:40Z[UTC]",
  "receivedDate": "2020-02-10T17:54:52Z[UTC]"
}
```

**Payload fields**

* **textMessage**: Plain text content of the email.
* **htmlMessage**: HTML-formatted content of the email.
* **attachments**: List of attachment filenames.
* **subject**: Email subject.
* **from**: Sender's email address.
* **to**: Recipient's email address.
* **cc**: Recipients in carbon copy.
* **bcc**: Recipients in blind carbon copy.
* **replyTo**: Email address for replies.
* **sentDate**: Timestamp when the email was sent.
* **receivedDate**: Timestamp when the email was received.
