Email from the shell: mutt and alpine
Reading mail in a terminal is faster than any webmail client once your fingers know it, and it works over a 3G tether from a train. Two clients are installed: mutt, which is a scalpel, and alpine, which is a menu.
There is no mail server on this box. Nothing is delivered locally,
/var/mailstays empty, and cron cannot email you its output. Both clients here are used the way you would use Thunderbird: they connect to your own provider over IMAP and send through its SMTP server.
mutt
Create ~/.mutt/muttrc (mode 0600 — it names your account):
set realname = "Your Name" set from = "you@example.com" # Reading: IMAP over TLS set folder = "imaps://imap.example.com/" set spoolfile = "+INBOX" set postponed = "+Drafts" set record = "+Sent" set imap_user = "you@example.com" # Sending: SMTP over TLS set smtp_url = "smtps://you@example.com@smtp.example.com:465/" # Keep a local copy of the mailbox so reopening is instant set header_cache = "~/.mutt/cache/headers" set message_cachedir = "~/.mutt/cache/bodies" set sort = threads set sort_aux = reverse-last-date-received
mkdir -p ~/.mutt/cache chmod 700 ~/.mutt chmod 600 ~/.mutt/muttrc
Run mutt. It will ask for your password twice — once for IMAP, once for the first send.
Not storing your password in a plain file
You can put set imap_pass = "..." in the config, and you should not: it is a plaintext password in your home directory on a shared machine. Either let mutt prompt you each session, or keep it encrypted:
gpg --quick-generate-key "you@example.com" # once, if you have no key printf 'set imap_pass = "yourpassword"\n' > /tmp/p printf 'set smtp_pass = "yourpassword"\n' >> /tmp/p gpg -e -r "you@example.com" -o ~/.mutt/pass.gpg /tmp/p shred -u /tmp/p
Then in muttrc:
source "gpg -dq ~/.mutt/pass.gpg |"
You unlock the key once per session instead of typing the password every time, and nothing readable sits on disk.
App passwords
Gmail, Outlook and most large providers will not accept your normal password from a mail client any more. Generate an app-specific password in your provider's account settings and use that. It also means revoking access from this box later is one click and does not disturb anything else.
Keys worth memorising
- j / k
- Next / previous message.
- Enter
- Read. q goes back.
- m
- Compose. r reply, g reply to all, f forward.
- d / u
- Mark deleted / undelete. $ applies the changes.
- c
- Change folder. ? lists your folders.
- /
- Search. l limits the view to matches, l then all restores it.
- s
- Save the message to a folder.
HTML mail
Most mail is HTML now. Render it inline with a text browser rather than giving up. Create ~/.mailcap:
text/html; w3m -dump -T text/html -o display_link_number=1 %s; copiousoutput; nametemplate=%s.html
and add to muttrc:
auto_view text/html alternative_order text/plain text/enriched text/html
Attachments
In a message, v lists the attachments; s saves the highlighted one. When composing, a attaches a file from your home directory — which is the easy way to mail yourself something you have built on the box.
alpine
Alpine is the friendlier option: everything is a menu and the commands are listed along the bottom of the screen at all times. It is the direct descendant of pine, which is what most people's first email client actually was.
Run alpine, then press S (Setup) and C (Config). The fields to fill in:
- Personal Name
- Your Name
- User Domain
example.com- SMTP Server
smtp.example.com:587/tls/user=you@example.com- Inbox Path
{imap.example.com:993/ssl/user=you@example.com}INBOX
E exits the config screen and Y saves. Settings live in ~/.pinerc, so you can edit that file directly once you know what you want.
Navigation is > and < to move in and out of screens, C to compose, Ctrl-X to send. Alpine's composer is the same editor as nano, which is the other reason people found it easy.
Which one
Use alpine if you want to read your mail today. Use mutt if you are going to live in it — its filtering, threading and macro system are why people who use mutt keep using mutt twenty years later.