# Email V2

The **Email V2** connector enables you to send simple emails in HTML format, with or without attachments.

## **Parameters**

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

### **General tab**

<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 Type</strong></td><td>Type of <a href="https://app.gitbook.com/s/jvO5S91EQURCEhbZOuuZ/platform-administration/settings/accounts">account used for authentication</a>. Supported: <strong>Azure Key</strong> and <strong>Basic</strong>.</td><td>Basic</td><td>String</td></tr><tr><td><strong>Account</strong></td><td>Account used to authenticate with the email server. Required if the service demands authentication. Supported: Azure Key and Basic.</td><td>N/A</td><td>String</td></tr><tr><td><strong>SMTP Host</strong> <code>(DB)</code></td><td>SMTP server host. Example: <code>smtp.gmail.com</code></td><td>smtp.gmail.com</td><td>String</td></tr><tr><td><strong>SMTP Port</strong> <code>(DB)</code></td><td>SMTP server port. Commonly 587, but may vary.</td><td>587</td><td>Integer</td></tr><tr><td><strong>From</strong> <code>(DB)</code></td><td>Sender's email address.</td><td>N/A</td><td>String</td></tr><tr><td><strong>To</strong> <code>(DB)</code></td><td>Recipient email address(es), separated by commas.</td><td>N/A</td><td>String</td></tr><tr><td><strong>CC</strong> <code>(DB)</code></td><td>CC recipient(s), separated by commas.</td><td>N/A</td><td>String</td></tr><tr><td><strong>BCC</strong> <code>(DB)</code></td><td>BCC recipient(s), separated by commas.</td><td>N/A</td><td>String</td></tr><tr><td><strong>Subject</strong> <code>(DB)</code></td><td>Email subject line.</td><td>N/A</td><td>String</td></tr><tr><td><strong>Charset</strong></td><td>Character set for the email body.</td><td>UTF-8</td><td>String</td></tr><tr><td><strong>Content</strong> <code>(DB)</code></td><td>Email body. Supports Freemarker templates for dynamic HTML.</td><td>N/A</td><td>String</td></tr><tr><td><strong>Custom Attachments Specification</strong></td><td>Enables raw attachment input and hides the form-based attachment field.</td><td>False</td><td>Boolean</td></tr><tr><td><strong>Attachments</strong></td><td>Email attachments. Specified via form or raw array.</td><td>N/A</td><td>Array of objects</td></tr><tr><td><strong>Authenticated</strong></td><td>Enable if SMTP authentication is required.</td><td>True</td><td>Boolean</td></tr><tr><td><strong>Is Over TLS</strong></td><td>Enable to send the message over TLS.</td><td>True</td><td>Boolean</td></tr><tr><td><strong>Is Over SSL</strong></td><td>Enable to send the message over SSL. Only available when <strong>Is Over TLS</strong> is disabled.</td><td>False</td><td>Boolean</td></tr><tr><td><strong>Socket Port</strong> <code>(DB)</code></td><td>Required if SSL is enabled. Specifies the port used. Only available when <strong>Is Over SSL</strong> is enabled.</td><td>N/A</td><td>Integer</td></tr><tr><td><strong>Force TLSv1.2</strong></td><td>Forces TLS 1.2 for secure email server connections. Only available when <strong>Is Over SSL</strong> is enabled.</td><td>False</td><td>Boolean</td></tr><tr><td><strong>Fail On Error</strong></td><td>If enabled, interrupts the pipeline execution when an error occurs. If disabled, execution continues, but the <code>"success"</code> property will be set to <code>false</code>.</td><td>False</td><td>Boolean</td></tr></tbody></table>

{% hint style="info" %}
To embed images in the email body,in the **Attachments** parameter use the prefix `cid:` followed by the image name. Example: `<img src="cid:image.png" />`
{% endhint %}

### **Documentation tab**

<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>Documentation</strong></td><td>Optional field to describe the connector configuration and any relevant business rules.</td><td>N/A</td><td>String</td></tr></tbody></table>

## **Message Flow**

### **Input**

No specific input is required unless a Double Braces expression is used in any field.

### **Output**

The connector returns a JSON object like the one below:

```json
{
  "from": "a@a.com",
  "to": "a@a.com,a@a.com.br",
  "cc": "a@a.com,a@a.com.br",
  "bcc": "a@a.com,a@a.com.br",
  "subject": "Subject",
  "content": "<html>Test Email!</html>",
  "charset": "UTF-8",
  "success": true,
  "attachments": [
    {
      "type": "ATTACHMENT",
      "attachment": "attachment.extension"
    }
  ]
}
```

**Field explanations:**

* `from`: Sender email
* `to`: Recipients
* `cc`: CC recipients
* `bcc`: BCC recipients
* `subject`: Email subject
* `content`: Email body (truncated if over 256 characters)
* `charset`: Character encoding used
* `success`: Indicates if the message was sent successfully
* `attachments`: List of attachments

{% hint style="info" %}
Files are handled securely within a temporary directory exclusive to the pipeline.
{% endhint %}

Learn more about [Messages processing](https://app.gitbook.com/s/jvO5S91EQURCEhbZOuuZ/development-cycle/build-overview/pipelines/messages-processing) in the Digibee Integration Platform.

## **Email V2 in action**

### **Authentication**

**Email V2** supports the following authentication methods:

**Basic**

* Use a Basic account where the **username** is the sender’s email and the **password** is the corresponding email password.

**OAuth 2**

{% hint style="warning" %}
Currently supported only for Microsoft-based (Outlook) email accounts.
{% endhint %}

To configure:

* Set the **From** field with the sender's email address.
* Choose an **Azure Key** that contains the necessary credentials.

Internally, the connector uses `client-id`, `client-secret`, and `tenant-id` to generate a token, which is used along with the sender email to authenticate with the SMTP server.

### **Example: Email with attachments and inline image (RAW mode)**

**Configuration:**

* **SMTP Host**: smtp.gmail.com
* **SMTP Port**: 587
* **From**: <email@gmail.com> (the same email configured in the **Account** parameter)
* **To**: <some_other_email@gmail.com>, <second_email@gmail.com>
* **Subject**: Hello
* **Content**:

```html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Demystifying Email Design</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<img src="cid:myImage.png" />
</body>
</html>
```

* **Authenticated**: true
* **Is Over TLS**: true
* **Attachment As Raw**: true
* **Attachments**:

```json
[
  { "type": "INLINE", "attachment": "myImage.png" },
  { "type": "ATTACHMENT", "attachment": "xpto.txt" }
]
```

**Output:**

```json
{
  "from": "email@gmail.com",
  "to": "some_other_email@gmail.com,second_email@gmail.com",
  "cc": "",
  "bcc": "",
  "subject": "Hello",
  "content": "<!DOCTYPE html PUBLIC ...TRUNCATED",
  "charset": "UTF-8",
  "success": true,
  "attachments": [
    { "type": "INLINE", "attachment": "myImage.png" },
    { "type": "ATTACHMENT", "attachment": "xpto.txt" }
  ]
}
```

### **Dynamic email example using Double Braces expressions**

You can use [**Double Braces expressions**](https://docs.digibee.com/documentation/connectors-and-triggers/double-braces/overview) to insert variables dynamically into your email configuration.

In the example below, we first configured the [**JSON Generator (Mock)**](https://docs.digibee.com/documentation/connectors-and-triggers/connectors/tools/json-generator) with the following data:

**JSON data:**

```json
{
  "sender": "digibee@gmail.com",
  "recipient": "digi@gmail.com",
  "recipient_cc": "digi1@gmail.com",
  "recipient_bcc": "digi2@gmail.com",
  "port": "587",
  "host": "smtp.gmail.com",
  "INVOICE": "98787979789",
  "DUE_DATE": "01/13/2023"
}
```

Next, we configured the **Email V2** connector using Double Braces expressions to reference these values:

* **SMTP Host:** `{{ message.host }}`
* **SMTP Port:** `{{ message.port }}`
* **From:** `{{ message.sender }}`
* **To:** `{{ message.recipient }}`
* **CC:** `{{ message.recipient_cc }}`
* **BCC:** `{{ message.recipient_bcc }}`
* **Subject:** `{{ CONCAT("Invoice ", FORMATDATE(NOW(), "timestamp", "MMMM yyyy", null, "UTC", "pt-BR", "GMT-3")) }}`
* **Charset**: `UTF-8: Eight-bit Unicode (or UCS) Transformation Format`
* **Content:**

```html
<!DOCTYPE html>
<html>
<head>
  </head>
<body>
 
Good afternoon, <br/>
Below is the invoice <a href='${INVOICE}'>(Click here)</a> referring to the monthly license fee for the platform – due for <b> ${DUE_DATE}</b>. <br/>
Payment will be via <b>bank transfer</b> - given in the body of the invoice. <br/><br/>


Please, confirm the receipt. <br/>
Any questions, we are available. <br/><br/>
  <br/>
  <br/>
Att.,
Customer relationship
</body>
</html>
```

### **Technology**

The connector uses [Freemarker](https://freemarker.apache.org/docs/dgui_template_exp.html) for dynamic content generation.
