前提確認
curl --version # protocols: に smtp, pop3, imap, ftp が含まれているか確認
SMTP / SMTPS
# SMTP (25番 or 587番) — メール送信テスト
curl smtp://mail.example.com:25 --mail-from sender@example.com --mail-rcpt recipient@example.com --upload-file mail.txt -v
# SMTP STARTTLS (587番)
curl smtp://mail.example.com:587 --mail-from sender@example.com --mail-rcpt recipient@example.com --upload-file mail.txt --ssl-reqd -v
# SMTPS (465番 — 最初からTLS)
curl smtps://mail.example.com:465 --mail-from sender@example.com --mail-rcpt recipient@example.com --upload-file mail.txt -v
# 認証あり
curl smtps://mail.example.com:465 -u "user@example.com:password" --mail-from user@example.com --mail-rcpt to@example.com --upload-file mail.txt -v
mail.txt の中身(最低限):
From: sender@example.com
To: recipient@example.com
Subject: test
Hello
POP3 / POP3S
# POP3 (110番) — メール一覧
curl pop3://mail.example.com -u "user:pass" -v
# 特定メール取得 (メッセージ番号1)
curl pop3://mail.example.com/1 -u "user:pass" -v
# POP3 STARTTLS
curl pop3://mail.example.com --ssl-reqd -u "user:pass" -v
# POP3S (995番)
curl pop3s://mail.example.com -u "user:pass" -v
IMAP / IMAPS
# IMAP (143番) — INBOXの一覧
curl imap://mail.example.com/INBOX -u "user:pass" -v
# 特定メール取得 (UID=1)
curl "imap://mail.example.com/INBOX;UID=1" -u "user:pass" -v
# IMAP STARTTLS
curl imap://mail.example.com/INBOX --ssl-reqd -u "user:pass" -v
# IMAPS (993番)
curl imaps://mail.example.com/INBOX -u "user:pass" -v
# フォルダ一覧
curl imaps://mail.example.com/ -u "user:pass" --request "LIST \"\" \"*\"" -v
FTP / FTPS
# FTP (21番) — ファイル一覧
curl ftp://ftp.example.com/ -u "user:pass" -v
# ファイルダウンロード
curl ftp://ftp.example.com/file.txt -u "user:pass" -o file.txt -v
# ファイルアップロード
curl ftp://ftp.example.com/upload.txt -u "user:pass" --upload-file upload.txt -v
# FTPS (Explicit TLS — STARTTLS方式, 21番)
curl ftp://ftp.example.com/ -u "user:pass" --ssl-reqd -v
# FTPS (Implicit TLS — 990番)
curl ftps://ftp.example.com/ -u "user:pass" -v
共通オプション
| オプション | 用途 |
|---|---|
-v |
詳細ログ(必須級) |
--ssl-reqd |
STARTTLSを強制 |
-k |
自己署名証明書を無視(テスト環境向け) |
--trace-ascii - |
バイナリ含む全通信ダンプ |
--resolve host:port:IP |
DNS代わりに直接IP指定 |
-u "user:pass" |
認証 |