Guide

Send iCloud Mail from the Command Line

Sending email through iCloud normally means configuring SMTP, generating app-specific passwords, and enabling 2FA. Nylas CLI sends iCloud Mail from Linux, macOS, and Windows terminals with one command. It works across 6 providers — Gmail, Outlook, Exchange, Yahoo, iCloud, and IMAP — with built-in OAuth2 and zero SMTP setup.

By Nick Barraclough

The problem with sending iCloud Mail from the terminal

Apple doesn't offer an API or CLI for iCloud Mail. The only programmatic option is SMTP through smtp.mail.me.com on port 587. That requires three prerequisites: two-factor authentication enabled on your Apple ID, an app-specific password generated at appleid.apple.com, and manual SMTP configuration in whatever tool you're using.

App-specific passwords don't support OAuth2 token refresh. They're static credentials that break if you reset your Apple ID password or revoke them. If you manage multiple iCloud accounts, you need a separate password for each one.

Nylas CLI bypasses all of this. It connects to the Nylas API, which handles iCloud authentication, token management, and connection pooling. Authenticate once, then send email with a single command.

1. Install Nylas CLI

# macOS / Linux (Homebrew)
brew install nylas/nylas-cli/nylas

# macOS / Linux / WSL (shell script)
curl -fsSL https://cli.nylas.com/install.sh | bash

# Windows (PowerShell)
irm https://cli.nylas.com/install.ps1 | iex

# From source (requires Go 1.23+)
go install github.com/nylas/cli/cmd/nylas@latest

2. Authenticate your iCloud account

Create an application at dashboard-v3.nylas.com and connect your iCloud mailbox. Then grab your API key:

nylas auth config
# Paste your API key when prompted

# Verify the connection
nylas auth whoami
# => Authenticated as you@icloud.com (iCloud)

Credentials are stored in your system keyring. You won't need to re-enter them unless you revoke the key.

3. Send a basic email

nylas email send \
  --to "friend@example.com" \
  --subject "Quick update" \
  --body "Hey, just wanted to share this link."

# Skip the confirmation prompt
nylas email send \
  --to friend@example.com \
  --subject "Quick update" \
  --body "Hey, just wanted to share this link." \
  --yes

After sending, the CLI confirms delivery:

✓ Email sent successfully

  Message ID: abc123def456
  To: friend@example.com
  Subject: Quick update
  Sent at: 2026-03-28T10:15:00-04:00

4. Send with attachments

nylas email send \
  --to "team@company.com" \
  --subject "March report" \
  --body "Attached is the report." \
  --attach ./march-report.pdf

# Multiple attachments
nylas email send \
  --to "team@company.com" \
  --subject "Design files" \
  --body "Here are the mockups." \
  --attach ./mockup-v1.png \
  --attach ./mockup-v2.png \
  --yes

iCloud Mail supports attachments up to 20 MB per message. For larger files, Apple's Mail Drop feature kicks in automatically when sending through Apple Mail, but that feature isn't available through SMTP or API-based sending.

5. Send HTML email

nylas email send \
  --to "subscriber@example.com" \
  --subject "Weekly digest" \
  --html "<h1>This Week</h1><p>Here's what happened.</p><ul><li>Item one</li><li>Item two</li></ul>" \
  --yes

6. CC and BCC recipients

nylas email send \
  --to "alice@team.com" \
  --cc "bob@team.com" \
  --bcc "manager@team.com" \
  --subject "Project status" \
  --body "All tasks on track for Friday." \
  --yes

7. Send from a custom domain or Hide My Email alias

iCloud+ subscribers can add up to 5 custom email domains and generate Hide My Email relay addresses. Once your iCloud account is connected, you can send from any of these addresses with the --from flag:

# Send from your custom domain
nylas email send \
  --to "client@example.com" \
  --from "hello@yourdomain.com" \
  --subject "Invoice #1042" \
  --body "Please find your invoice attached." \
  --attach ./invoice-1042.pdf \
  --yes

# Send from a Hide My Email relay address
nylas email send \
  --to "newsletter@service.com" \
  --from "abc123@privaterelay.appleid.com" \
  --subject "Unsubscribe" \
  --body "Please remove me from your list." \
  --yes

Hide My Email addresses route replies back to your real inbox. The recipient never sees your @icloud.com address.

8. JSON output for scripting

Add --json to get structured output you can pipe into jq or feed to an automation:

nylas email send \
  --to "user@example.com" \
  --subject "Test" \
  --body "Automated send" \
  --yes \
  --json
{
  "id": "msg_a1b2c3d4",
  "grant_id": "d3f4a5b6-c7d8-9e0f-a1b2-c3d4e5f6g7h8",
  "subject": "Test",
  "from": [{"name": "You", "email": "you@icloud.com"}],
  "to": [{"email": "user@example.com"}],
  "date": "2026-03-28T10:30:00-04:00",
  "object": "message"
}

iCloud SMTP vs Nylas CLI

StepiCloud SMTPNylas CLI
Enable 2FARequiredNot needed
Generate app-specific passwordRequired (appleid.apple.com)Not needed
Configure SMTP host/portsmtp.mail.me.com:587Not needed
TLS/STARTTLS setupManualAutomatic
Token refreshNo (static password)Automatic
Custom domain sendingRequires SMTP config per domainUse --from flag
Hide My EmailRequires relay SMTP configUse --from flag
JSON outputNoYes (--json)
Multi-provider supportiCloud onlyGmail, Outlook, Exchange, Yahoo, iCloud, IMAP

Apple-specific tips

Sending limits

Apple caps iCloud Mail at 1,000 outgoing messages per day, with a maximum of 500 recipients per message. According to Apple's iCloud system requirements, these limits apply to all sending methods. If you hit the limit, messages bounce until the 24-hour window resets.

Hide My Email relay addresses

Hide My Email generates random addresses like abc123@privaterelay.appleid.com. Replies route to your real inbox. You can create and deactivate these addresses from iCloud settings or the Settings app on iOS/macOS. They work with Nylas CLI the same way they work with Apple Mail.

Custom domain sending

iCloud+ lets you add up to 5 custom domains. Each domain needs DNS verification (MX and TXT records pointing to Apple). Once verified, you can send from those domains through Nylas CLI with --from. The domain must be fully verified in iCloud settings before it'll work.

Next steps