Receive and send email
This guide is for authors who want an automation to work from a mailbox: start a run when an email arrives, read what it carries, and answer it. Three blocks do the work:
- Email received starts a run for each email you choose.
- Reply to email answers an email in its own thread.
- Send email sends a new email.
1. Connect a mailbox
Section titled “1. Connect a mailbox”Open Connections, click New connection, and choose Outlook email account or Gmail account under Email. Creating one needs Connections: Manage in the workspace, which the Lead role has.
Before you click Connect, decide on Allow sending:
- Off: automations can only read the mailbox.
- On: they can also send and reply as it.
This can’t be changed after connecting. To change it, create a new connection and point the automations at it. Turn it on only for a mailbox that should send.
Click Connect and sign in to the mailbox in the window that opens. The connection reads the mailbox of the account that signs in, so use an account made for the work rather than a person’s own inbox. In a Microsoft 365 organization, an administrator may need to approve Lainstack before a work mailbox can connect.
2. Start a run for the emails you want
Section titled “2. Start a run for the emails you want”Create an automation and add Email received from the block library. Under Email account, pick the connection.
Under Which emails, say which emails start a run. Leave it empty and every email does.
- Only start for takes up to 20 filters, and all of them must match. Each compares From, To, Cc or Subject with Contains, Does not contain, Equals, Does not equal, Starts with, Ends with, Is empty or Is not empty. Case doesn’t matter.
- For To and Cc, a filter matches when any address on the email does. Does not contain and Does not equal need every address to pass.
- Only with attachments skips emails that carry no files.
- Skip automatic replies is on by default, so out-of-office replies and delivery failures start no run. It reads the email’s headers, and some senders don’t set them.
For example, to start only for emails from one company that carry files:
| Field | Comparison | Value |
|---|---|---|
| From | Ends with | @example.com |
| Only with attachments | On |
Filter here rather than with a Condition later. A filtered email starts no run and isn’t downloaded or stored. A Condition still starts a run for every email and keeps a copy of each. Below the filters, the block shows how many emails it filtered out in the last 7 days.
Several automations can listen on the same mailbox, each with its own filters. An email that matches two of them starts a run in each.
What never starts a run
Section titled “What never starts a run”- Email from before. Only email that arrives after the automation is published starts a run. What’s already in the mailbox is left alone.
- Anything outside the Inbox. Email in Junk (Spam on Gmail), or moved to another folder by a mailbox rule, starts no run unless it’s moved back to the Inbox. Mark a sender as safe so their email isn’t sent to Junk.
- The mailbox’s own email. Email the mailbox sent itself never starts a run, so an automation that replies can’t answer its own replies. On Outlook this is judged by the address Microsoft reports for the account. On a personal Microsoft account signed in with another provider’s address, email from that address starts no run even when it was sent from elsewhere.
- Very large email. An email over about 50 MB, counting the encoding added to its attachments, isn’t processed. The block counts it as too large to process.
Junk, own email and email from before aren’t counted as filtered out.
The mailbox is checked about once a minute, so a run starts shortly after an email arrives, not instantly.
3. Use what the email holds
Section titled “3. Use what the email holds”Later blocks map the trigger’s outputs with @:
| Output | Holds |
|---|---|
| From, To, Cc, Subject | The addresses and subject. To and Cc are lists. |
| Body Text | The message as plain text, up to 64 KiB. Longer text is cut off. |
| Attachments | Each attached file. |
| The whole message as one file. | |
| Message Id | The email’s id. Reply to email needs it. |
| In Reply To, References | The thread the email belongs to. In Reply To is empty when the email isn’t a reply. |
| Received At, Account Email | When it arrived, and the mailbox’s address as the provider reports it. |
The last three rows are run details: when you type @, they’re listed after the other values.
To read an attachment, map Attachments into an AI Agent block’s Files, and put Subject and Body Text in its User message when the email itself says something useful, such as a reference. See Read data from a document. AI Agent reads PDFs, images and plain text such as CSV, up to 10 files in one step. Other files, such as spreadsheets or a forwarded email attached as a file, make the step fail, so check the file type first when senders vary.
Don’t send the Email file to AI Agent. It’s the raw message, which AI Agent can’t read.
Treat what an email says as untrusted: anyone can write to the mailbox. On a block that reads email, leave AI Agent’s Workspace access and Write access off, or crafted text in an email could get the agent to send workspace data out.
4. Test before you publish
Section titled “4. Test before you publish”Open the trigger’s Samples tab and fill in an example email, or capture one from a past run. The tab says whether that email would start a run, and if not, which filter it fails. It starts nothing. A sample you fill in has no attachments, so with Only with attachments on it shows as filtered out, though a draft run can still use it.
Then click Run draft and choose Pinned sample or A past run to try the rest of the automation. To test reading files, publish and send a real email first, then run the draft on that run. See Runs in the editor.
To test the trigger itself, publish the automation, send a real email to the mailbox and check Runs. If no run appears, look in Junk, and check the filtered-out count under the filters.
5. Reply or send
Section titled “5. Reply or send”Both blocks need a connection with Allow sending on. They send plain text, without Bcc.
Reply to email answers in the original thread:
- Email connection: the mailbox the email arrived in.
- Message Id: map the trigger’s Message Id.
- Reply to all: off answers the sender only. On answers everyone on the email.
- Body: the text. Type
@to add values from earlier blocks. - Attachments: optional files.
If the email has left the mailbox by the time the step runs, the step fails and says so.
Send email starts a new email, with To, Cc (one address, or several separated by commas), Subject, Body and Attachments. Use it to tell someone other than the sender, such as a colleague, or to send a summary on a Schedule.
Limits for both:
- Attachments can be up to 3 MB in total. Above that the step fails and nothing is sent.
- A connection sends up to 500 emails a day, new emails and replies together.
- A draft run holds at these blocks and sends nothing. Later blocks get the block’s example values instead.
An AI Agent can write the text, and a block sends it: map the agent’s answer into Body. An agent can’t send email through a job. To check the text before it goes out, put an Approval in front of the send.
6. When a send fails
Section titled “6. When a send fails”A send either went out, was refused, or can’t be confirmed:
- Refused: nothing was sent, and the step says why. For example, the connection can only read mail, or the mailbox needs reconnecting.
- Couldn’t confirm: the step fails with “Couldn’t confirm this email was sent.” The email may have gone out. Check Sent Items in the mailbox before you do anything else.
A send is never retried by itself. If you resume a run at a failed send, it sends again, so after “Couldn’t confirm” resume only when Sent Items shows nothing went out.