2.8 KiB
2.8 KiB
iCloud Mail Setup
Connect iCloud Mail to the messenger platform via IMAP/SMTP.
Prerequisites
- An iCloud account with an @icloud.com / @me.com email address
- Two-factor authentication enabled on the Apple ID
- An app-specific password (regular password won't work with 2FA)
1. Generate an App-Specific Password
- Go to appleid.apple.com
- Sign in, navigate to Sign-In and Security > App-Specific Passwords
- Click Generate an app-specific password
- Label it
messenger-sync(or similar) - Copy the generated password (format:
xxxx-xxxx-xxxx-xxxx)
2. Configure Environment Variables
Add to the backend .env file:
# iCloud Mail IMAP (incoming)
ICLOUD_IMAP_HOST=imap.mail.me.com
ICLOUD_IMAP_PORT=993
ICLOUD_IMAP_USER=yourname@icloud.com
ICLOUD_IMAP_PASS=xxxx-xxxx-xxxx-xxxx
ICLOUD_IMAP_TLS=true
# iCloud Mail SMTP (outgoing)
ICLOUD_SMTP_HOST=smtp.mail.me.com
ICLOUD_SMTP_PORT=587
# Your iCloud email (used to determine message direction)
ICLOUD_FROM_EMAIL=yourname@icloud.com
# Sync interval in milliseconds (default: 60000 = 1 minute)
ICLOUD_SYNC_INTERVAL=60000
ICLOUD_IMAP_USER and ICLOUD_IMAP_PASS use the same app-specific password for both IMAP and SMTP.
3. IMAP/SMTP Server Details
| Protocol | Host | Port | Security |
|---|---|---|---|
| IMAP | imap.mail.me.com | 993 | TLS |
| SMTP | smtp.mail.me.com | 587 | STARTTLS |
4. What Gets Synced
On startup, the ICloudSyncService:
- Connects to IMAP
- Syncs folder list (Inbox, Sent, Drafts, etc.) to
email_folderstable - Fetches messages from each folder (last 30 days on first sync)
- Parses email headers for threading (
References,In-Reply-To) - Creates contacts from sender/recipient addresses
- Stores messages with
provider = 'icloud'in the unifiedmessagestable - Polls for new messages on the configured interval
5. Verify Sync
Once the backend is running with iCloud configured:
-- Check synced folders
SELECT name, message_count, unread_count FROM email_folders WHERE provider = 'icloud';
-- Check synced messages
SELECT COUNT(*) FROM messages WHERE provider = 'icloud';
-- Check conversations
SELECT display_name, message_count FROM conversations WHERE provider = 'icloud' ORDER BY last_message_at DESC LIMIT 10;
Or via MCP tools:
list_conversations provider=icloud
list_folders provider=icloud
search_messages query="..." provider=icloud
Troubleshooting
- "ICLOUD_IMAP_USER not configured" — The env var is empty or missing. Check
.env. - Authentication failed — Verify the app-specific password. Regular Apple ID passwords don't work.
- Connection timeout — Ensure outbound connections to
imap.mail.me.com:993are allowed. - No messages syncing — First sync fetches the last 30 days. Check
email_foldershas entries first.