# Email task

An Email task sends a mail: to tell somebody that files arrived, that a job failed, or to send the files themselves.

It uses the mail server that is set up for the whole server in the [Preferences](Prefs.md), unless you give it one of its own.

## Fields

| Field | What it does | On a new task |
|---|---|---|
| **From** | the sender. Empty: the server's usual sender. | |
| **To**, **CC**, **BCC** | the recipients, several separated by commas | |
| **Reply To** | where answers go | |
| **Subject** | | |
| **Body Format** | **HTML** or **Plain Text** | HTML |
| **Body** | the text | |
| **Attach Files?** | the files on the list are attached | off |
| **Loop through items?** | one mail **per file**. Unticked: one mail for all files. | off |
| **Delay between loops in seconds** | a pause between those mails | 0 |
| **Retry** … **times with** … **seconds delay.** | when sending fails | 1, 1 |

Every field takes [variables](Jobs-Variables.md): `{user_email}` as the recipient in a job that an event started, `{name}` in the subject, `{task_error}` in the body.

## One mail for many files

Without the loop, the mail is about all the files the task's filter matches. Two things make that readable:

- `{items_count}` is how many there are.
- A part of the body between `{line_start}` and `{line_end}` is repeated for every file:

```
{items_count} files were delivered today:

{line_start}{name}  {size_formatted}
{line_end}
```

Outside those markers, `{name}` and the other values of a file are those of the first file.

## Links to the files

In the body, a share link to each file can be made on the spot:

| Written | Makes |
|---|---|
| `{share:reference:7}` | a link to the file where it is, good for 7 days |
| `{share:copy:7}` | a copy of the file is shared; the original can go |
| `{share:move:7}` | the file is moved into the share |

The first part of the address is yours to write: `https://files.example.com/{share:reference:7}`. When a link is missing from the mail, `{share:reference:7:message}` puts the reason in its place.

A link is the better attachment: it has no size limit, and it can expire.

## A mail server of the task's own

| Field | What it does |
|---|---|
| **Use custom SMTP settings** | the task does not use the server's mail settings but these |
| **SMTP Server Used for Emailing** | host and port: `smtp.example.com:587` |
| **SMTP Server Username**, **SMTP Server Password** | |
| **SSL/TLS** | the connection is encrypted |
| **HTML** | the mail is sent as HTML |
| **Test SMTP Settings** | sends a test |
| **Get Refresh Token** | for Google and Microsoft mail, which do not take a password: signs in once and stores a token. The fields for it appear when the server's name is one of theirs. |
| **Load and use mime types for email attachments.** | attachments are labelled with their kind, so that a mail program opens them with the right application |

Use this where a job has to send as another sender than the server does, through that sender's own mail server.

## What it hands on

The items it was given, unchanged.

## Things to know

- **With an empty list** the mail is still sent, once. A report "0 files today" needs no item.
- **The filter decides the attachments.** With the task's filter `*.zip`, only the zip is attached and counted, whatever else is on the list.
- **Folders are not attached.** Files on other servers are fetched for attaching.
- **Mail has limits.** Most mail servers refuse messages over 10 to 25 MB. For anything larger, send a link.
- **When it fails**, the task fails with the mail server's answer in the log. The usual causes are a wrong password and a sender address the mail server does not allow.
- **A failure mail** is an Email task named `Default Failure`: see [When a job fails](Jobs-Failures.md).
- **Passwords in the log.** Addresses in a mail are written without their passwords.
