Skip to content

Instantly share code, notes, and snippets.

@bradhowes
Last active January 21, 2024 12:02
Show Gist options
  • Save bradhowes/e4db684fa782f913d0454750bb103c72 to your computer and use it in GitHub Desktop.
Save bradhowes/e4db684fa782f913d0454750bb103c72 to your computer and use it in GitHub Desktop.
Using msmtp on macOS with iCloud
  • Install msmtp using brew install msmtp
  • Configure msmtp using the following:
# Set default values for all the accounts.
defaults
auth on
logfile ~/.maildir/msmtp.log
port 587
protocol smtp
tls on
# tls_trust_file ~/.maildir/certificates/root-certificates.pem

account default
host smtp.mail.me.com
from <EMAIL_ADDRESS>
user <EMAIL_ADDRESS>
passwordeval security find-generic-password -s msmtp-icloud -a <EMAIL_ADDRESS> -w

Of course, replace <EMAIL_ADDRESS> with something valid.

Create an app token to allow msmtp to authenticate with smtp.mail.me.com without using your iCloud password. See https://support.apple.com/en-us/102654

Use Keychain Access app to create a new application password entry. Name the entry msmtp-icloud and set the account to be <EMAIL_ADDRESS> -- basicallly, match the arguments given above in the passwordeval line. Go to the "Access Control" tab and allow for all applications.

Test that msmtp works OK:

% echo "this is a test" | msmtp -d -- <EMAIL_ADDRESS>
ignoring system configuration file /opt/homebrew/Cellar/msmtp/1.8.25/etc/msmtprc: No such file or directory
loaded user configuration file /Users/blahblah/.msmtprc
falling back to default account
using account default from /Users/blahblah/.msmtprc
host = smtp.mail.me.com
port = 587
source ip = (not set)
proxy host = (not set)
proxy port = 0
socket = (not set)
timeout = off
protocol = smtp
domain = localhost
auth = choose
user = <EMAIL_ADDRESS>
password = *
passwordeval = security find-generic-password -s msmtp-icloud -a <EMAIL_ADDRESS> -w
ntlmdomain = (not set)
tls = on
tls_starttls = on
tls_trust_file = system
tls_crl_file = (not set)
tls_fingerprint = (not set)
tls_key_file = (not set)
tls_cert_file = (not set)
tls_certcheck = on
tls_min_dh_prime_bits = (not set)
tls_priorities = (not set)
tls_host_override = (not set)
auto_from = off
maildomain = (not set)
from = <EMAIL_ADDRESS>
from_full_name = (not set)
allow_from_override = on
set_from_header = auto
set_date_header = auto
remove_bcc_headers = on
undisclosed_recipients = off
dsn_notify = (not set)
dsn_return = (not set)
logfile = /Users/blahblah/.maildir/msmtp.log
logfile_time_format = (not set)
syslog = (not set)
aliases = (not set)
reading recipients from the command line
<-- 220 iCloud SMTP - st43p00im-ztfb10073301.me.com 3.8.4 (2408BSE6-83985e98c480)
--> EHLO localhost
<-- 250-st43p00im-ztfb10073301.me.com
<-- 250-PIPELINING
<-- 250-SIZE 28319744
<-- 250-ETRN
<-- 250-STARTTLS
<-- 250-ENHANCEDSTATUSCODES
<-- 250-8BITMIME
<-- 250-DSN
<-- 250-SMTPUTF8
<-- 250 CHUNKING
--> STARTTLS
<-- 220 2.0.0 Ready to start TLS
TLS session parameters:
    (TLS1.3)-(ECDHE-SECP256R1)-(RSA-PSS-RSAE-SHA256)-(AES-256-GCM)
TLS certificate information:
    Subject:
        C=US,ST=California,O=Apple Inc.,CN=smtp.mail.me.com
    Issuer:
        CN=Apple Public Server RSA CA 12 - G1,O=Apple Inc.,ST=California,C=US
    Validity:
        Activation time: Tue Jan 16 12:29:58 2024
        Expiration time: Mon Jan 20 12:39:58 2025
    Fingerprints:
        SHA256: 35:99:C0:A2:9C:29:FB:A2:97:9B:99:8A:E0:AB:3D:BF:D4:22:2F:7A:D2:82:F4:59:2F:AD:C3:9A:94:D9:5D:D5
        SHA1 (deprecated): A2:2D:9D:64:C9:EB:B5:77:A8:98:E9:66:9F:8B:3B:78:B3:43:BA:29
--> EHLO localhost
<-- 250-st43p00im-ztfb10073301.me.com
<-- 250-PIPELINING
<-- 250-SIZE 28319744
<-- 250-ETRN
<-- 250-AUTH LOGIN PLAIN ATOKEN WSTOKEN WETOKEN
<-- 250-ENHANCEDSTATUSCODES
<-- 250-8BITMIME
<-- 250-DSN
<-- 250-SMTPUTF8
<-- 250 CHUNKING
--> AUTH PLAIN ...........
<-- 235 2.7.0 Authentication successful
--> MAIL FROM:<EMAIL_ADDRESS>
--> RCPT TO:<EMAIL_ADDRESS>
--> DATA
<-- 250 2.1.0 Ok
<-- 250 2.1.5 Ok
<-- 354 End data with <CR><LF>.<CR><LF>
--> From: <EMAIL_ADDRESS>
--> Date: Sun, 21 Jan 2024 12:46:13 +0100
--> Message-ID: <..........>
--> this is a test
--> .
<-- 250 2.0.0 Ok: queued as 224AB800075
--> QUIT
<-- 221 2.0.0 Bye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment