Reference for sending email from the terminal on Arch Linux.

Installed Packages

PackagePurpose
msmtpLightweight SMTP client — relays mail through an external SMTP server (e.g., Gmail)
s-nailProvides mail and mailx commands for composing and sending email from the CLI
aercFull-featured TUI email client — read, compose, reply, manage folders, all in the terminal
mailcapMIME type handling — maps file types to applications for mail attachments

Getting Started

Install everything:

sudo pacman -S msmtp s-nail aerc

The setup order matters — each tool builds on the previous:

  1. msmtp first — this is the foundation. It handles SMTP authentication and sending. Nothing else can send mail without it.
  2. s-nail next — gives you quick mail one-liners. It uses msmtp automatically.
  3. aerc last — the full email client. It can use msmtp for sending (outgoing via SMTP) and connects directly to Gmail via IMAP for reading.

You’ll need a Google App Password for both msmtp and aerc. Generate one per app, or share the same one. Requires 2-Step Verification on your Google account.

msmtp

The SMTP relay. It doesn’t receive or read mail — it just sends outbound messages through a configured SMTP server.

Config: ~/.msmtprc (must be chmod 600)

defaults
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile        ~/.msmtp.log

account        gmail
host           smtp.gmail.com
port           587
from           you@gmail.com
user           you@gmail.com
password       <app-password>

account default : gmail

Gmail setup: Requires a Google App Password (2-Step Verification must be enabled first). Regular passwords won’t work.

Send directly with msmtp:

printf "Subject: Hello\n\nBody text here" | msmtp recipient@example.com

Check logs: ~/.msmtp.log shows delivery status for every send attempt.

s-nail (mail / mailx)

User-friendly CLI for composing email. Uses msmtp as the transport when available.

Send a quick email:

echo "Message body" | mail -s "Subject line" recipient@example.com

Send with an attachment:

mail -s "Subject" -a /path/to/file.pdf recipient@example.com < body.txt

Interactive compose:

mail recipient@example.com

Type the message, then press Ctrl+D to send.

Config: ~/.mailrc (optional — s-nail finds msmtp automatically if installed)

set mta=/usr/bin/msmtp

aerc

A terminal UI email client — think of it as a modern mutt. Supports multiple accounts, threads, vim-style keybindings, an embedded terminal for composing with your $EDITOR, and HTML rendering.

Config directory: ~/.config/aerc/

FilePurpose
accounts.confIMAP/SMTP account credentials
aerc.confMain config (UI, keybindings, filters, compose settings)
binds.confCustom keybindings

Account setup (~/.config/aerc/accounts.conf):

[Gmail]
source   = imaps://trevorchaney%40gmail.com@imap.gmail.com:993
outgoing = smtp+plain://trevorchaney%40gmail.com@smtp.gmail.com:587
default  = INBOX
from     = Trevor Chaney <trevorchaney@gmail.com>
copy-to  = Sent
source-cred-cmd = cat ~/.config/aerc/gmail-pass
outgoing-cred-cmd = cat ~/.config/aerc/gmail-pass

The gmail-pass file contains your App Password. Make sure it’s locked down:

chmod 600 ~/.config/aerc/accounts.conf
chmod 600 ~/.config/aerc/gmail-pass

Usage:

aerc                # launch the client

Key commands inside aerc:

KeyAction
j/kMove up/down message list
EnterOpen message
CCompose new message
rrReply all
qQuit
:Command mode

Composing opens your $EDITOR (configured as nvim in aerc.conf). Save and quit the editor to go back to aerc, then :send to send.

Saved attachments go to ~/pars/storage/email by default (configured in aerc.conf).

How They Fit Together

Sending (one-liner):   mail/mailx → msmtp → smtp.gmail.com → recipient
Sending (aerc):        aerc → smtp.gmail.com → recipient
Reading (aerc):        aerc ← imap.gmail.com ← Gmail inbox

For quick sends, mail pipes through msmtp. For reading and managing email, aerc connects directly to Gmail over IMAP. aerc can also send directly via SMTP without msmtp, but having msmtp configured means mail one-liners work too.

Plus Addressing

Gmail supports + tags for filtering: you+tag@gmail.com delivers to you@gmail.com but preserves the tag in the To: header. Useful for tracking where email comes from:

echo "Test" | mail -s "From website" contact+site@yourdomain.com
echo "Test" | mail -s "From resume" contact+resume@yourdomain.com

Filter in Gmail by To: contact+site@yourdomain.com to auto-label or sort.