Terminal Email Client with Raspberry PI and Mutt

Check my RPI articles in Best Raspberry PI projects article or peppe8o.com home page. Or subscribe my newsletter (top right in this page) to be notified when new projects are available! Also interested to start 3D printing with a cheap budget? Visit my cheap 3D printers list
0
(0)

We are all get used to beautiful email clients. Smartphones, computers and tablets are plenty of open source email management software to make life really easy and communicate with high value tools.

But sometimes, when some nerds (like me) love working with terminal, an email client inside your terminal ca save looking continuously on another screen to check messages arrived.

One of most known solution to this need is Mutt. This is a small but very powerful text-based mail client for Unix operating systems.

From Wikipedia Mutt page:

Though written from scratch, Mutt’s initial interface was based largely on the ELM mail client. To a large extent, Mutt is still very ELM-like in presentation of information in menus (and in fact, ELM users will find it quite painless to switch as the default key bindings are identical). As development progressed, features found in other popular clients such as PINE and MUSH have been added, the result being a hybrid, or “mutt.” At present, it most closely resembles the SLRN news client. Mutt was originally written by Michael Elkins

Raspberry PI Zero W

It is highly customizable and you can configure your own macros to manage email triggers. Supports both POP3 and IMAP protocols.

In this tutorial I’m going to show you how install and use Mutt in your Raspberry PI OS Lite (without Desktop Environment). I’ll use a cheap Raspberry PI Zero W for this guide, but it applies also to newer Raspberry Pi boards.

What You Need

As usual, I suggest adding from now to your favourite ecommerce shopping chart all needed hardware, so that at the end you will be able to evaluate overall costs and decide if continuing with the project or removing them from shopping chart. So, hardware will be only:

High speed micro SD Card is not strictly required for this software, but it is useful if you will make other projects on same PI requiring high resources load.

Check hardware prices with following links:

Amazon raspberry pi boards box
Amazon raspberry pi Zero W box
Amazon Micro SD box
Amazon Raspberry PI Power Supply box

Step-by-Step Procedure

Install Operating System

We’ll start installing Raspberry PI OS Lite (headless and high performance OS). This guide applies also to Raspberry PI OS Desktop installations, using its internal terminal.

Make your OS updated. From terminal, issue following command:

sudo apt update -y && sudo apt upgrade -y

Install and Setup Mutt

To install Mutt, we can use the convenient aptitude package manager already available in all Rasberry PI OS distributions:

sudo apt install mutt

Next commands will create folders used for improve mutt performance with caching. The “-p” option in mkdir will create subdirectories (parents) with a single command:

mkdir -p ~/.mutt/cache/headers
mkdir ~/.mutt/cache/bodies

Create a new Mutt configuration file:

nano ~/.mutt/muttrc

For a very simple and basic IMAP configuration, please use following template. It is based on Gmail settings, so you should check IMPS and SMTP configurations for your email provider. Also mail tree could change based on your provider folders organization (some email prodivers may use, for example, “INBOX.SENT” instead of “[Gmail]/Sent Mail”

Change also “email@gmail.com”, “youSecretPassword”, “email” and “User Alias” with your ones.

#================ IMAP ====================
set imap_user = email@gmail.com
set imap_pass = youSecretPassword
set spoolfile = imaps://imap.gmail.com/INBOX
set folder = imaps://imap.gmail.com/
set record="imaps://imap.gmail.com/[Gmail]/Sent Mail"
set postponed="imaps://imap.gmail.com/[Gmail]/Drafts"
set mbox="imaps://imap.gmail.com/[Gmail]/All Mail"
set header_cache = "~/.mutt/cache/headers"
set message_cachedir = "~/.mutt/cache/bodies"
set certificate_file = "~/.mutt/certificates"

#================ SMTP ====================
set smtp_url = "smtp://email@smtp.gmail.com:587/"
set smtp_pass = $imap_pass
set ssl_force_tls = yes

#================ Composition ====================
set editor = "nano"
set edit_headers = yes
set charset = UTF-8 # value of $LANG; also fallback for send_charset
# Sender, email address, and sign-off line must match
unset use_domain
set realname = "User Alias"
set from = "email@gmail.com"
set use_from = yes
set timeout = 30

Once finished, save and exit. You can now test your SMTP configuration by sending a test email directly from terminal with following command (set your test recipient address):

echo "Email test message body" | mutt -s "Subject here" recipient@example.com

You can also send email with attachment in a similar way, by appending at the end the “-a” option and file path (absolute or relative):

echo "Please find file attached" | mutt -s "Attachment test" recipient@example.com -a "/home/pi/testfile.jpg"

You can now verify also IMAP configuration by accessing your mailbox with mutt client. From terminal:

mutt

This will result in your mailbox email list:

Mutt terminal email client home

Please find below some useful commands.

In list view:

  • ENTER -> focus on selected email
  • up/down ARROWS -> scroll emails
  • q -> quite
  • m -> compose new email (CTRL+C to interrupt composition)
  • d -> mark message to be deleted (on mutt exit a delete confirmation will be requested)
  • u (on a message before a marked to delete one and then “u” again) -> unmark message from deletion

In email view:

  • ENTER -> scroll message down
  • DEL -> scroll message up
  • i -> exit from message and go back to list view
  • up, down, left and right ARROWS -> navigate between different messages

Moreover, with “?” key you can get a complete help showing how to use Mutt.

More advanced features can be found in Mutt Gitlab page.

Enjoy! … but …

Before the greetings, did you found the Easter Egg in this tutorial? No?!?! See carefully screenshot! Yes? Write down in comments and challenge your friends to find it!

How useful was this post?

Click on a star to rate it anonymously!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?