# Gmail and mailboxes

> Connect a mailbox you already have, Gmail included, so new mail starts flows. Covers the IMAP connection, the app password, the trigger's settings and what Lumen does to your mail.

Source: https://docs.go-lumen.ai/he/connectors/gmail-and-mailboxes

A mailbox connection lets Lumen read a mailbox that already exists, so a new email there can start a flow with no forwarding rule and no change to your mail settings. Gmail, Yahoo, iCloud and any company mail server that speaks IMAP connect the same way.

-   10 minutes
-   Needs an app password
-   Admin to connect

## How Gmail connects

Gmail connects as a **Mailbox (IMAP)** connection, signed in with a Google **app password**. There is no "Sign in with Google" button: a native Gmail connection with Google sign-in is planned and not available yet.

If you have a Microsoft 365 or Outlook mailbox, use [Microsoft 365](https://docs.go-lumen.ai/he/connectors/microsoft-365.md) instead. Microsoft has largely retired password sign-in over IMAP, so Lumen offers an approval-based connection for it.

## Reading or forwarding

|  | Email forwarding | Mailbox (IMAP) |
| --- | --- | --- |
| How mail reaches Lumen | You add a rule that forwards a copy to a Lumen address. It arrives the moment it is sent. | Lumen signs in to the mailbox and checks it every few minutes (5 by default). |
| What you change | A forwarding rule in your mail. | Nothing in your mail settings, but you give Lumen a password. |
| What Lumen can see | Only what you forward. | The folder you point a flow at. |
| Best for | A shared address, or when you cannot give out a password. | A mailbox you cannot add rules to. |

See [Email forwarding](https://docs.go-lumen.ai/he/connectors/email-forwarding.md) for the first one.

## Connect a mailbox

Create an app password first. Google does not accept your normal password over IMAP.

1.  In your Google account, turn on **2-Step Verification**.
2.  Open **App passwords** and create one named `Lumen`. Google shows 16 letters. Spaces are fine.
3.  In a Google Workspace account, an admin must allow app passwords first.

Then connect it. Yahoo and iCloud work the same way with their own app passwords (an iCloud one keeps its dashes).

**Console:**

1.  In the sidebar, open **Connectors**, click **Add connection** and choose **Mailbox (IMAP)**.
2.  Give it a **Name**, such as `Accounting inbox`.
3.  Under **Server**, enter `imap.gmail.com`. Leave **Port** at `993` and **Encryption** at **TLS (recommended)**.
4.  Under **User name**, enter the full address. Under **Password**, paste the app password.
5.  Click **Test connection**. Lumen signs in and lists the mailbox's folders. Then click **Add Mailbox (IMAP)**.

![The Add connection panel for Mailbox (IMAP). Name holds Accounting inbox. Server holds imap.gmail.com. Port is 993. Encryption offers TLS (recommended, selected), STARTTLS and None (development only). User name holds accounting@example.com. Skip certificate check is switched off. Password is filled with hidden characters. Test connection, Cancel and Add Mailbox (IMAP) are at the bottom.](https://docs.go-lumen.ai/he/img/connectors/gmail-and-mailboxes-01-imap-form.png)

*The mailbox form. The password is kept apart from the connection and never shown again.*

**Skip certificate check** and the **None** encryption choice are for development. With either on, anyone on the network could read the mail or pose as your server, and the console warns you.

**CLI:**

```bash title="Connect Gmail from a terminal"
lumen connect imap-mailbox accounting-inbox --preset gmail \
  --set username=accounting@example.com \
  --secret-env password=GMAIL_APP_PASSWORD
```

`--preset gmail` fills in the server, port and encryption and shows Google's app password guide. Presets also exist for `yahoo`, `icloud` and `other`. Run it with no flags and it asks for each value, with the password hidden. Secrets are never taken as a flag value.

**YAML:**

```yaml title="accounting-inbox.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Connector
metadata:
  name: accounting-inbox
  namespace: tenant-acme
spec:
  classRef: {name: imap-mailbox}
  config:
    host: imap.gmail.com
    port: 993
    security: tls
    username: accounting@example.com
  credentials:
    secretRef: {name: lumen-conn-accounting-inbox}
```

The password is a Kubernetes Secret in the workspace's namespace, named `lumen-conn-accounting-inbox`, with one key, `password`. Never put it in the resource. Writing it through the console or `lumen connect` creates the Secret for you.

If the test fails, the message says why: the mailbox refused the user name or password (for Gmail, Yahoo and iCloud that usually means a normal password was used), the server could not be reached, the secure connection failed, or the server did not answer in time.

## Start a flow from new mail

Add the trigger **An email arrives**, set **Source** to **Your mailbox**, and pick the mailbox under **Which mailbox starts this flow?**.

![The settings of the trigger An email arrives in a mailbox. Source is set to Your mailbox. Which mailbox starts this flow shows office@example.com, Mailbox (IMAP). Folder to watch shows the placeholder INBOX. After the flow has the email offers Mark it as read (selected), Move it to a folder and Leave it as it is. Check every (minutes) is 5 and Include attachments is switched on.](https://docs.go-lumen.ai/he/img/connectors/gmail-and-mailboxes-02-trigger.png)

*The same trigger as for forwarded mail, with Your mailbox as the source.*

| Setting | Default | What it does |
| --- | --- | --- |
| **Folder to watch** (`folder`) | `INBOX` | The mailbox folder to read. Pick one from the connection's folders, or type a name. |
| **After the flow has the email** (`afterHandling`) | **Mark it as read** | **Mark it as read**, **Move it to a folder**, or **Leave it as it is**. |
| **Check every (minutes)** (`pollMinutes`) | 5 | How often Lumen looks, 1 to 60. |
| **Include attachments** (`includeAttachments`) | On | Take the message's files. |
| **Attachments** (`attachments`) | **Each attachment separately** for a new trigger | One document per file, or **The whole email as one**. |
| **Largest mail (MB)** (`maxSizeMB`) | 25 | A bigger message is recorded and not downloaded. 1 to 40. |
| **Only emails with an attachment** (`requireAttachment`) | Off | A mailbox trigger takes every message unless you turn this on. |
| **Import existing mails (newest)** (`importExisting`) | 0 | Also take the newest N messages already in the folder, once, when the trigger is first switched on. 0 to 500. |
| **Start only when** (`when`) | None | A condition on the email's own fields. A message that does not match starts no run and is left in the mailbox, not marked read or moved. |

The trigger gives the same fields as a forwarded email: `from`, `to`, `subject`, `body`, `attachments`, `senderVerified`, `receivedAt` and `messageId`. A reply or forward step after it works the same way. How attachments become documents is described in [Email forwarding](https://docs.go-lumen.ai/he/connectors/email-forwarding.md#attachments-and-limits), and the limits there apply here, with **Largest mail (MB)** going up to 40.

```yaml title="mailbox-invoices.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: mailbox-invoices
  namespace: tenant-acme
spec:
  displayName: File invoices from the accounting inbox
  triggers:
    - id: email
      ref: {name: mailbox-email}
      connectorRef: {name: accounting-inbox}
      config:
        folder: INBOX
        afterHandling: {mode: moveTo, folder: Processed}
        pollMinutes: 5
        attachments: separate
        requireAttachment: true
      when: {field: email.subject, op: contains, value: invoice}
      next: [pdfs]
  nodes:
    - id: pdfs
      stepRef: {name: keep-pdfs}
      next: [keep]
    - id: keep
      stepRef: {name: save-file}
      config: {destination: lumen, folder: "Invoices/{date:yyyy-MM}"}
```

In YAML the trigger for this source is [`mailbox-email`](https://docs.go-lumen.ai/he/reference/triggers/mailbox-email.md). The console shows it as **An email arrives** with **Source** set to **Your mailbox**, and a flow saved either way runs the same.

## How checking works

-   **A new trigger starts from now.** Mail already in the folder is not touched unless you set **Import existing mails (newest)**.
-   **At most 50 messages per check.** A bigger backlog is worked off over the next checks.
-   **Each message starts one run per flow, once.** Lumen remembers the Message-ID, so a message is never handled twice by the same flow, even when a check repeats.
-   **Check now.** In the trigger's **Recent emails**, an admin can click **Check the mailbox now** to read it at once instead of waiting. A second request within 30 seconds is refused.
-   **When the mailbox cannot be read**, Lumen retries with a growing delay (up to 30 minutes), marks the connection **Not working** with the reason (the mailbox cannot be reached, it refused the sign-in, or the folder is missing), and tells the workspace's admins once. It clears the warning when the mailbox reads again. Editing the connection triggers a retry at once.
-   **Sender verification.** `senderVerified` comes from the authentication header your mail server added when it received the message. Gmail, Microsoft 365 and Exchange Online add one. A server that does not leaves the result only as good as the header the sender wrote.

## What Lumen can do in your mailbox

An IMAP password cannot be limited to part of a mailbox. Whoever holds it has the mailbox's full IMAP access, so treat the app password like a key, and revoke it in your Google account if you disconnect.

What Lumen does with it:

-   It reads the folders a flow watches, and the messages that arrive in them.
-   After a flow takes a message it marks it as read, moves it, or leaves it, as you chose.
-   It does not delete mail, and it does not send mail through IMAP. A flow's **Send it to me by email** step sends from Lumen's own address. To send as the mailbox itself, use [Microsoft 365](https://docs.go-lumen.ai/he/connectors/microsoft-365.md).

Lumen stores the password apart from the connection, uses it only when it checks the mailbox, and never shows it again.

## Next steps

[Email forwardingStart flows from mail you forward to a Lumen address, with no password.](https://docs.go-lumen.ai/he/connectors/email-forwarding.md)[Microsoft 365Connect an Outlook mailbox and a SharePoint folder with an admin approval.](https://docs.go-lumen.ai/he/connectors/microsoft-365.md)[TriggersEvery way to start a flow, and the Start only when condition.](https://docs.go-lumen.ai/he/build/triggers.md)[When a run failsWhat happens when a step fails and how to read why.](https://docs.go-lumen.ai/he/build/when-a-run-fails.md)
