Neomutt

From Void Linux Wiki
Jump to: navigation, search

Neomutt

Neomutt[1] is a highly configurable and minimalistic mail client written for terminal. Initially the project was called Mutt, but the development slowed down and several community patches never made it into the code. The patches were later picked up by Neomutt and documentation has since been brought up to speed. Neomutt is known to be complicated to set up and not have that many features therefore, this page is dedicated to get you started. Note that this guide is mostly working towards setting Neomutt up with a gmail account. However, Neomutt works with a lot of different providers.

Installing

sudo xbps-install -S neomutt cyrus-sasl cyrus-sasl-modules cyrus-sasl-modules-gssapi

Setting up neomutt

There is only need for two config files to get neomutt to a working state .neomuttrc and a config for the mailadr you are connecting to neomutt. Both files can be placed in ~/.config/neomutt and the config for the mailadr should be sourced to neomuttrc like so:

source "~/config/neomuttrc/gmail"

This is a sample of the config. Please change it to your needs. If you chose to put passwords in the config, you should also consider changing the permissions of the config, or Neomutt will throw an error. Alternatively, you can type in your pass at each connect and each time you send a mail.

# imap
set imap_user =  "your@mail.com"
set imap_pass =  "supersecretpassword"

# smtp
set smtp_url =   "smtp://username@smtp.gmail.com:587/"
set smtp_pass =  "$imap_pass"

# folders
set spoolfile =  "+INBOX"
set mbox =       "+[Gmail].all Mail"
set postponed =  "[Gmail].All Mail"

# settings
set from =       "$imap_user"
set editor =     "vim"

General Settings

After installing Neomutt you can copy the neomuttrc from /etc/neomuttrc however, this is a 8000 lines config plus documentation where you only need few lines to get things working. It’s advised to read through the documentation since Neomutt has a lot of features.

Secure passords

Nothing here yet

Viewing attachments

If a file is attached to a mail you can either download the file to your computer or setup the mailcap which also can be located in ~/.config/neomutt. This file will tell Neomutt which program should be used to each type of file. This can be extended to the files of your choosing. Before this works, this needs to be added to the neomuttrc:

set mailcap_path =   "~.config/neomutt/mailcap"
auto_view =          "yes"
alternative_order =  "no"

Here is an example of the mailcap:

# PDF
application;mupdf %s
image/pdf;mupdf %s

# Images
image/bmp;feh %s
image/gif;feh %s
image/libm;feh %s
image/jpg;feh %s
image/jpeg;feh %s
image/png;feh %s
image/tiff;feh %s
image/x-png;feh %s

html/plain text

Most mail today is sent like rich text in html which is unreadable by default in Neomutt. This can be fixed by telling Neomutt how to handle emails not sent in plain text. Add this line to mailcap

text/html w3m -I %{charset} -T text/html; copiousoutput

Keybindings

By pressing “?” whilst in Neomutt, you’ll be presented with a list of functions which you can bind. i.e. for more vim-like moving around in Neomutt:

Note that both colors and keybindings are set up in the same way. First indicate what you want to do “bind” then tell Neomutt where this change should occur “index” then the key “d” and the function “delete-message”.

bind index j next-line
bind index k previous-line
bind index D delete-message
bind index d half-down
bind index u half-up

Editor

It’s possible to write mails in neomutt just by pressing m (mail) or r (reply) and then write out the mail in the same window as the index of neomutt. However, it’s also possible to use your own

Debug

Some times it might be nice to know why neomutt fails or what it actually does. Either start neomutt with the level of debug you’d like neomutt -d 2. This can also be set in the neomutrc is there is a need for always having debug logs Add these two lines:

debug file =   "~/.config/neomutt/debug/"
debug_level =  "2"

Sidebar

Neomutt has a built in sidebar which gives an overview of the folders on the mailserver. Default it’s bound to shift+b. The sidebar can also be opened by default when opening neomutt by adding the following to neomuttrc:

set sidebar_visible = "yes"

Urls

Opening urls are quite easy in Neomutt by installing urlview and make a macro in the neomuttrc where ctrl+b will make urlview skim for links:

macro index,pager \cb     "<pipe-message> urlview<Enter>"
macro attach,compose \cb  "<pipe-entry> urlview<Enter>"

Offlineimap/msmtp

Neomutt only looks at the server which it is being directed to. However, it’s also possible to download all mail from the server to read/write mail even offline. This is done by offlineimap and msmtp. First install both:

sudo xbps-install -S offlineimap msmtp

Hereafter, there needs to be created two configs .offlineimaprc and .msmtprc which both resides in ~/.

The config for offlineimap:

[general]
accounts =         "yourmailconfig"
starttls =         "yes"
autorefresh =      "1"

[Account gmail]
localrepository =  "yourmailconfig-local"
remoterepository = "youremailconfig-remote"

[Repository yourconfig-remote]
type = gmail
remoteuser =       "yourusername"
remotepass=        "supersecretpassword"
sslcarcertfile =   "etc/ssl/certs/ca-certificates.crt"

[Repository yourmailconfig-remote]
type =             "Maildir"
localfolders =     "~/.mail/yourmailconfig"

The config for msmtp:

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

account         "yourmailconfig"
host            "smtp.gmail.com"
port            "587"
from            "your@email.com"
password        "supersecretpassword"

account default "yourmailconfig"

Now run the command offlineimap -a yourmailconfig and your mail will be downloaded from the server. First time this make take some time, but later this will take 2-5 seconds to check the server and get new e-mails. To make sure new e-mails are collected from the server, a cron-command should be set up offlineimap -a yourmailconfig.

E-mail notification

Neomutt has its own function for sending a command if you have new mail [2]. If you are the type of person who uses i3wm and i3status, you can make your own script for letting you know if new mail has arrived you can use the script below and point it to i3 in the bar-section of the config.

#!/bin/bash

i3status | while :
do
	maildirs=”$HOME/.mail/*/INBOX/new/”
	ml=”$(find $maildirs -type f | wc -1)”
	read line
	echo “New Mails: $ml | $line” || exit 1
done

Alternatives

Neomutt

- Alpine[3]

- Sup[4]

Offlineimap

- getmail[5]

- mbsync[6]

Troubleshooting

Nothing here yet.