====== Terminal Email with Mutt ======
[[http://www.mutt.org|Mutt]] is a terminal and CLI email client for sending, receiving, and reading email. It uses vim-like keybindings and has minimal requirements. If you want to use a GUI email client, try [[https://www.thunderbird.net/|Thunderbird]]. You might also be interested in [[https://neomutt.org|Neomutt]].
===== Setup =====
Let's look at how to obtain, install, and configure Mutt for use.
==== Install =====
You can download Mutt from [[http://www.mutt.org]] as a pre-built binary or as source code. Many Linux distributions will have a package for it already.
**Install with package manager on Debian**
sudo apt install mutt
**Build from source**
Here are the steps to build from source. You can download the sources from [[http://www.mutt.org]].
wget ftp://ftp.mutt.org/pub/mutt/mutt-2.0.6.tar.gz
tar xzf mutt-2.0.6.tar.gz
cd mutt-2.0.6
./configure --help | less # First check all options
# Include any desired options
./configure --enable-smtp --enable-imap --with-ssl --enable-compressed \
--enable-sidebar --enable-autocrypt --with-sqlite3 --with-zlib --with-sasl
make
# The executable you need is now at `./mutt`.
sudo make install # Optional
NOTE: If you're trying to build in MacOS and it says it can't find SSL, run:
brew install openssl
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
# Then run ./configure with the options.
To see what flags were used when mutt was built, run ''mutt -v'' and look for Configure options:
# See what build options mutt used
mutt -v
==== Configure ====
Use the ''~/.muttrc'' file to configure things like:
* Your name and from address
* Credentials for sending with SMTP and receiving with IMAP
* Which editor to use when composing
For a list of all options, try running ''man muttrc''.
You can also set any of these values while you're already inside Mutt by running the commands like:
:set sort=reverse-last-date-received
Here is an example ''$HOME/.muttrc'' file.
# ~/.muttrc
# Identity
set from = "john.doe@example.com"
set realname = "John Doe"
# Sending mail with SMTPS
# TLS is `smtps://` and port 465
# non-TLS `smtp://` and port 25 or 587
set smtp_url = "smtps://nanodano@devdungeon.com@mail.devdungeon.com:465/"
set smtp_pass = "password"
# Receiving mail with IMAPS
# TLS is `imaps://` with port 993
# non-TLS `imap://` with port 143
# Omit password, and it will prompt you
set imap_user = "nanodano@devdungeon.com"
set imap_pass = "password"
set folder = "imaps://mail.devdungeon.com:993"
set spoolfile = "+INBOX"
# Automatically fetch mailbox folders from server
set imap_check_subscribed = yes
# Turn on sidebar showing folders
set sidebar_visible = yes
# Set editor when composing
set editor = "vim"
# Sorting
# Default sort will put oldest emails at top `last-date-received`
# Use `reverse-last-date-received` to have newest messages at top
set sort = reverse-last-date-received
# or try `set sort = threads`
# Colors (general)
color normal white default
color status cyan default
color indicator brightcyan default
color tree magenta default
color error brightred default
color message brightmagenta default
# Color headers
color header brightyellow default "^from:"
color header yellow default "^to:"
color header yellow default "^cc:"
color header blue default "^date:"
color header brightblue default "^subject:"
# Color bodies
color attachment brightblack default
color search red brightblack
color signature cyan default
color tilde blue default
# Color URLs
color body brightblue default "(^|<| )mailto:[^ ]+@[^ ]( |>|$)"
color body brightblue default "(^|<| )(http|https|ftp)://[^ ]+( |>|$)"
# Quoted emails
color quoted magenta default
color quoted1 cyan default
color quoted2 green default
color quoted3 magenta default
color quoted4 cyan default
color quoted5 green default
color quoted6 magenta default
color quoted7 cyan default
===== Basics =====
To get more information, try the man page, the '--help' option, and going into mutt and pressing the ''?'' key.
man mutt
man muttrc
mutt --help
mutt # Go into mutt and press ?
==== Send email ====
You can compose an email message directly from CLI or from within Mutt.
To send email from within Mutt, simply press ''m'' and it will begin composing a new mail. If you had any postponed mails (drafts) it will ask if you want to load those or start a new one.
To send email via the CLI, invoke mutt like this:
# Email nanodano
mutt -s "Test Email" nanodano@devdungeon.com
# Attach file with `-a`
mutt -s "Test Attachment" nanodano@devdungeon.com -a file.zip
==== Reading email ====
Assuming your ''~/.muttrc'' is configured with the proper IMAP server and credentials, all you have to do is open ''mutt'' and it will automatically connect and pull your mail. When you open ''mutt'' you'll be presented the list of emails. Use the vim keybinds to get around.
There are some letters that show up next to emails that represent different things like:
* No letter means the email has been read
* ''O'' means the email has not been opened
* ''r'' means the email has been replied to
* ''D'' means the email is marked for deletion
Keybinds:
* ''?'' to get help and a list of keybinds
* ''q'' to quit
* ''j'' and ''k'' or ''up'' and ''down'' to move through the list of emails
* ''right'' and ''left'' arrow keys will page down and up
* ''space'' or ''enter'' to read the selected email from the list
* ''q'' or ''i'' to stop reading an email and go back to the list of emails
* ''r'' to reply
* ''d'' to mark for deletion
* ''/'' to open the search form; ''n'' to keep finding next occurrences
To change sort order interactively, use '':set sort=last-date-received'' or '':set sort=reverse-last-date-received''.
===== Check other folders =====
To check other folders besides your basic inbox, you can manually set the mailbox names in ''.muttrc'' or you can have it automatically fetch all folders from the IMAP server. You can also show the sidebar to see what folder you're currently looking in.
# In your ~/.muttrc
# To automatically fetch folders from IMAP server
set imap_check_subscribed = yes
# To manually set folders
mailboxes =INBOX =INBOX.Sent =Inbox.Trash
# It's also useful to show the sidebar
set sidebar_visible = yes
To change what folder you're looking in, press the ''y'' key.
===== Check multiple email accounts =====
One way to do this is have separate ''.muttrc'' files for different accounts, and then specify the the rc file to use at runtime:
mutt -F ~/.muttrc.account2
If you want to include a generic rc file within your account specific file, use ''source'' to load the other scripts source. For example:
# ~/.muttrc.account2
# Load generic colors/preferences
source ~/.muttrc
### Account specific settings ###
set from = "john.doe@example.com"
set realname = "John Doe"
set smtp_url = "smtps://nanodano@devdungeon.com@mail.devdungeon.com:465/"
set smtp_pass = "password"
# Omit password, and it will prompt you
set imap_user = "nanodano@devdungeon.com"
set imap_pass = "password"
set folder = "imaps://mail.devdungeon.com:993"
set spoolfile = "+INBOX"
I read that there is a way to map a key-bind to toggle switching between mailboxes like this but I'm not sure how. Press ''?'' in mutt to pull up the commands. Probably something like "load rc file" followed by "sync mailbox imap".
You can also use the Dialog tool. Refer to the page: [[other:dialog_terminal_tui|Dialog - Terminal Menu Creator]], but here is a simple example:
#!/bin/bash
# Present a list of accounts to choose from
exit_code=0
exec 3>&1
# Go back to the menu after quitting mutt
while [ $exit_code -eq 0 ]
do
# Generate a menu of accounts
choice=$(dialog --menu "Open mail" 40 40 40 \
"~/.muttrc.1" "Account 1" \
"~/.muttrc.2" "Account 2" \
2>&1 1>&3)
exit_code=$?
if [ $exit_code -eq 0 ]
then
mutt -F "$choice"
fi
done
exec 3>&-
===== Use PGP encryption =====
//Incomplete. To Do.//