imap_search_emails
Find emails by criteria like sender, subject, body, or date range. Search a single folder or across all folders (skipping trash/spam/drafts) to locate messages when you don't know the UID.
Instructions
Search for emails matching criteria (sender, recipient, subject, body text, date range, read/flagged status). Use this to FIND messages when you know something about them but not their UID — e.g. "emails from amazon last week", "unread invoices". By default searches a single folder (INBOX). Set searchAllFolders=true to scan every mailbox at once — this catches messages filed away by rules (e.g. a receipt routed to a custom folder); Trash/Spam/Drafts are skipped unless you opt in. Returns lightweight headers (uid, from, subject, date, and folder when searching across folders); call imap_get_email with a returned uid + folder to read full content. For the newest messages without criteria, prefer imap_get_latest_emails.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | No | Search by recipient | |
| body | No | Search in body text | |
| from | No | Search by sender | |
| seen | No | Filter by read/unread status | |
| limit | No | Maximum number of results | |
| since | No | Search emails since date (YYYY-MM-DD) | |
| before | No | Search emails before date (YYYY-MM-DD) | |
| folder | No | Folder name to search (default: INBOX). Ignored when searchAllFolders is true. | INBOX |
| flagged | No | Filter by flagged status | |
| subject | No | Search by subject | |
| accountId | No | Account ID (from imap_list_accounts). Optional if accountName is given or only one account is configured. | |
| messageId | No | Search by RFC822 Message-ID header (substring match) | |
| accountName | No | Account name instead of accountId. Optional if accountId is given or only one account is configured. | |
| includeSpam | No | When searchAllFolders is true, also search Spam/Junk folders (off by default — noisy). | |
| includeTrash | No | When searchAllFolders is true, also search Trash/Bin/Deleted folders (off by default — noisy). | |
| includeDrafts | No | When searchAllFolders is true, also search the Drafts folder (off by default). | |
| searchAllFolders | No | Search across ALL folders instead of just `folder`. Skips Trash/Spam/Drafts and non-selectable folders by default. Use when a message might have been filed/archived/moved and you do not know which folder it is in. |