SMTP 要分清楚伺服器對伺服器的 TCP 25、用戶端 submission 的 587+STARTTLS,以及 465 implicit TLS。Port 通不代表 relay、登入或寄信一定成功。
DNS 與 TCP 可達性
查 MXPowerShell
Resolve-DnsName example.com -Type MX先按 Preference 找正確 mail exchanger。
用 dig 查 MXLinux/macOS
dig +short MX example.com確認不是把根網域 A record 當 SMTP 主機。
測 SMTP 25PowerShell
Test-NetConnection mail.example.com -Port 25 -InformationLevel Detailed成功只代表 TCP handshake;ISP/雲端可能限制 outbound 25。
測 submission 587PowerShell
Test-NetConnection smtp.example.com -Port 587之後還要驗證 STARTTLS 與認證方法。
測 implicit TLS 465PowerShell
Test-NetConnection smtp.example.com -Port 465465 是連線一開始就 TLS,不要加 STARTTLS。
查 PTRPowerShell
Resolve-DnsName 203.0.113.25 -Type PTR寄信 IP 的 PTR 通常應對回合理 hostname,且正向也能對上。
STARTTLS 與憑證
測 TCP 25 STARTTLSOpenSSL 3.x
openssl s_client -connect mail.example.com:25 -starttls smtp -servername mail.example.com -brief確認 protocol、cipher、verification 與伺服器 banner。
測 TCP 587 STARTTLSOpenSSL 3.x
openssl s_client -connect smtp.example.com:587 -starttls smtp -servername smtp.example.com -brief587 通常需要 authenticated submission。
測 TCP 465 implicit TLSOpenSSL 3.x
openssl s_client -connect smtp.example.com:465 -servername smtp.example.com -brief不要加 -starttls smtp。
顯示完整憑證鏈OpenSSL
openssl s_client -connect smtp.example.com:587 -starttls smtp -servername smtp.example.com -showcerts檢查 server 是否送出需要的 intermediate。
乾淨送出 QUITLinux/macOS
printf 'QUIT\r\n' | openssl s_client -connect mail.example.com:25 -starttls smtp -servername mail.example.com -brief -ign_eof避免 s_client 等 server 主動關閉而卡住。
查看憑證日期與名稱Linux/macOS
openssl s_client -connect smtp.example.com:587 -starttls smtp -servername smtp.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltNameSNI hostname 要和使用者實際設定一致。
SMTP 對話與實際寄送
只測 EHLO 能力swaks
swaks --server mail.example.com --port 25 --quit-after EHLO看 SIZE、STARTTLS、AUTH 等 extension,不會送信。
測 STARTTLS 到 TLS 完成swaks
swaks --server smtp.example.com --port 587 --tls --quit-after TLS只測協商,不提供帳密。
指定寄件與收件測內部 relayswaks(核准測試環境)
swaks --server relay.corp.example --from [email protected] --to [email protected] --quit-after RCPT停在 RCPT,不送 DATA;只測自己管理的收件人。
用 curl 測 SMTP 能力curl
curl --verbose --url 'smtp://mail.example.com:25' --ssl-reqd可能停在協定互動;用於測 TLS 與 banner,不代表送信成功。
建立最小測試郵件PowerShell
@('From: [email protected]','To: [email protected]','Subject: SMTP test','','test') | Set-Content .\smtp-test.eml -Encoding ascii不放真實敏感內容,完成後依紀錄政策刪除。
用 curl 寄核准測試信curl(測試帳號)
curl --url 'smtp://relay.corp.example:25' --mail-from '[email protected]' --mail-rcpt '[email protected]' --upload-file smtp-test.eml只對允許來源與自家網域;不能拿來探測 open relay。
怎麼確認有做對
- TCP、EHLO、STARTTLS、憑證名稱/鏈、MAIL FROM、RCPT TO 分階段記錄結果。
- 寄送測試信時在寄件端 log、郵件追蹤與收件端 header 對到同一個 Message-ID。
- 從實際設備所在 VLAN 測,不只在郵件伺服器本機測。
常見錯誤
- 看到 220 banner 就判定寄信正常。
- 把 465 當成 587 的替代 port,或對 465 下 STARTTLS。
- 在命令列直接放真實 SMTP 密碼。
- 拿不屬於自己的網域測試 relay。
常見問題
Port 25 通,為什麼還是不能寄?
TCP 通只證明連得上。還要看對方接受的寄件者、收件者、relay policy、TLS、驗證、DNS、信譽與實際 SMTP 回覆碼。
587 和 465 應該選哪個?
依服務商文件。587 通常是 submission 加 STARTTLS;465 是 implicit TLS。不要靠換 port 猜,還要核對 AUTH/OAuth 要求。
延伸閱讀
版本與官方文件
參數會隨工具版本與作業系統實作改變。正式環境先用 --help、-h 或系統內建說明確認,再以當版官方文件為準。
常見問題
Port 25 通,為什麼還是不能寄?
TCP 通只證明連得上。還要看對方接受的寄件者、收件者、relay policy、TLS、驗證、DNS、信譽與實際 SMTP 回覆碼。
587 和 465 應該選哪個?
依服務商文件。587 通常是 submission 加 STARTTLS;465 是 implicit TLS。不要靠換 port 猜,還要核對 AUTH/OAuth 要求。