Skip to content
Skip to main content

How to list iCloud email messages

Last updated:

Apple doesn’t offer a public email API for iCloud Mail. There’s no REST interface, no SDK, and no developer portal for mail. The only programmatic access is raw IMAP, and even that requires each user to manually create an app-specific password through their Apple ID settings. Nylas handles all of that and exposes iCloud through the same Messages API you use for Gmail and Outlook.

This guide covers listing messages from iCloud accounts, including the app-specific password requirement, the 90-day message cache, and iCloud-specific behaviors you should know about.

No. Apple publishes no public REST API or SDK for iCloud Mail, and there’s no developer portal for it. The only programmatic access is IMAP for reading and SMTP for sending, and each user must generate a 16-character app-specific password from their Apple ID account page before any client can connect.

That constraint is why most iCloud integrations go through a layer that wraps IMAP. Reading mail still happens over IMAP, which exposes the last 90 days through the message cache, with older messages reachable on demand. This guide uses a unified REST layer so the same call that lists Gmail or Outlook messages also lists iCloud mail across all 6 providers.

How do I list iCloud Mail messages with the Nylas API?

Section titled “How do I list iCloud Mail messages with the Nylas API?”

Send a GET request to /v3/grants/{grant_id}/messages using the iCloud connector and your API key. The endpoint returns the 50 most recent messages by default and up to 200 per page. iCloud is IMAP-backed, so only messages within the 90-day sync cache are searchable server-side. See List messages for the request and response.

iCloud’s biggest friction point for developers is the app-specific password requirement. There’s no way to generate these programmatically, so every user must log in to their Apple ID, open the security settings, and manually create a password before your app can connect. On top of that, you carry the full IMAP burden.

That means building the same infrastructure as any other IMAP integration: connection management, MIME parsing, sync state tracking, and a separate SMTP connection for sending.

Nylas handles the IMAP connection and guides users through the app password flow during authentication. You get a REST API with JSON responses, automatic sync and caching, and the same code works across iCloud, Gmail, Outlook, Yahoo, and every other provider.

If you’re comfortable with raw IMAP and only targeting iCloud, you can connect directly. For multi-provider apps or faster development, Nylas saves you significant time.

You’ll need:

  • A Nylas application with a valid API key
  • A grant for an iCloud Mail account
  • An iCloud connector configured in your Nylas application

iCloud requires app-specific passwords for third-party email access. Unlike Google or Microsoft OAuth, there’s no way to generate these programmatically. Each user must create one manually in their Apple ID settings.

Nylas supports two authentication flows for iCloud:

MethodBest for
Hosted OAuthProduction apps where Nylas guides users through the app password flow
Bring Your Own (BYO) AuthenticationCustom auth pages where you collect credentials directly

With either method, users need to:

  1. Go to appleid.apple.com and sign in
  2. Navigate to Sign-In and Security then App-Specific Passwords
  3. Generate a new app password
  4. Use that password (not their regular iCloud password) when authenticating

The full setup walkthrough is in the iCloud provider guide and the app passwords guide.

Make a List Messages request with the grant ID. By default, Nylas returns the 50 most recent messages. These examples limit results to 5:

Apple ships no email API, so iCloud Mail is IMAP-only and every user must create a 16-character app-specific password before any client connects. Once that grant exists, the Nylas CLI reads the mailbox like any other connected account, with no IMAP client code on your side. The nylas email list command pulls the inbox straight from your terminal.

The Nylas CLI mirrors the Messages API, so you can read the same inbox from your terminal without writing any code. After nylas init and nylas auth login, the email list command returns the 10 most recent inbox messages by default and pages through everything automatically once --limit goes over 200:

# List the 10 most recent inbox messages
nylas email list
# Show only unread messages from a specific sender
nylas email list --unread --from [email protected]
# Fetch everything across all folders, paginated automatically
nylas email list --all --all-folders --max 500

To find specific messages rather than list them, email search runs a full-text query with its own filters for sender (--from), date range (--after and --before), and attachments (--has-attachment). Search returns 20 results by default and only fetches more than one page once --limit goes over 200:

# Full-text search restricted to one sender, attachments only
nylas email search "invoice" --from [email protected] --has-attachment

Both commands accept --json, so you can pipe results into jq or a script. See the email list and email search command reference for every flag.

iCloud folder names aren’t fixed. They vary by account and can be locale-specific, so a German account stores trash under Papierkorb rather than Deleted Messages. The Apple Mail display name also won’t always match the IMAP folder on the server. List each account’s real names first, then read one by name:

# Folder names vary per account, so list the real ones first
nylas email folders list
# Read a folder by its actual iCloud name
nylas email list --folder "Sent Messages"

iCloud keeps roughly 90 days of mail searchable through the cache. iCloud sending runs through the same CLI. See Send email from the terminal for the send commands.

You can narrow results with query parameters. Here’s what works with iCloud accounts:

ParameterWhat it doesExample
subjectMatch on subject line?subject=Weekly standup
fromFilter by sender[email protected]
toFilter by recipient[email protected]
unreadUnread only?unread=true
inFilter by folder or label ID?in=INBOX
received_afterAfter a Unix timestamp?received_after=1706000000
received_beforeBefore a Unix timestamp?received_before=1706100000
has_attachmentOnly results with attachments?has_attachment=true

Here’s how to combine filters. This pulls unread messages from a specific sender:

iCloud supports the search_query_native parameter for IMAP-style search. Like Yahoo, iCloud isn’t subject to the in, limit, and page_token co-parameter restriction that Google and Microsoft enforce, so you can pair it with standard filters like from and subject.

See the search best practices guide for more on search_query_native across providers.

iCloud is IMAP-based, which means it shares some behaviors with Yahoo and other IMAP providers. But Apple has its own quirks too.

Nylas maintains a rolling cache of messages from the last 90 days for all IMAP-based providers, including iCloud. Anything received or created within that window is synced and available through the API. For older messages, set query_imap=true to query iCloud’s IMAP server directly. This is slower but gives you access to the full mailbox.

When using query_imap, you must include the in parameter to specify which folder to search.

Nylas webhooks only fire for changes to messages within the 90-day cache window. If a user modifies or deletes a message older than 90 days, you won’t receive a notification. Plan your sync strategy accordingly if your app needs to track changes across the full mailbox.

iCloud uses standard IMAP folder names, but the exact names can vary. Some accounts use locale-specific names (for example, “Papierkorb” instead of “Trash” on German accounts), and the display name in Apple Mail may not always match the IMAP folder name on the server.

Common folder names on English-language accounts:

Apple Mail UI nameFolder name
InboxINBOX
SentSent Messages
DraftsDrafts
TrashDeleted Messages
JunkJunk
ArchiveArchive

Don’t hardcode these. Always use the List Folders endpoint to discover the exact folder names for each account.

Apple publishes specific sending limits for iCloud Mail:

LimitValue
Messages per day1,000
Recipients per day1,000
Recipients per message500
Max message size20 MB

These are sending limits, not read limits. Nylas handles retries if you hit throttling on reads, but if your app sends email through iCloud accounts, keep these limits in mind. Source: Apple support documentation.

iCloud doesn’t support List-Unsubscribe-Post or List-Unsubscribe custom headers when sending email. If your app sends subscription-style email through iCloud accounts, you’ll need to handle unsubscribe links in the message body instead. This limitation is shared with some Microsoft Graph accounts.

The Contacts API is disabled by default for iCloud grants. If your app needs to access iCloud contacts, contact Nylas Support to enable it. When enabled, contacts are parsed from email headers (From, To, CC, BCC, Reply-To fields) rather than synced from an address book.

iCloud accounts use IMAP for reading and SMTP for sending. This is invisible to your code, but it affects a few behaviors:

  • Sync relies on IMAP idle. Nylas maintains low-bandwidth connections to monitor the Inbox and Sent folders. Other folders are checked periodically, so changes outside Inbox and Sent may take a few minutes to appear.
  • Message IDs are IMAP UIDs, which are numeric values unique within a folder but not globally unique across the account. If you need a stable identifier across folders, use the Message-ID header.
  • Thread grouping relies on subject-line and In-Reply-To header matching. This works well for most conversations but isn’t as precise as Gmail’s native threading.

You can authenticate iCloud accounts two ways in Nylas:

MethodProvider typeWhat you get
iCloud connectoricloudEmail through IMAP plus calendar through CalDAV
Generic IMAPimapEmail only, no calendar access

Use the dedicated iCloud connector if your app needs calendar access alongside email. The generic IMAP connector works for email-only use cases but doesn’t include CalDAV support.

The Messages API returns paginated responses. When there are more results, the response includes a next_cursor value. Pass it back as page_token to get the next page:

Keep paginating until the response comes back without a next_cursor.