6am: Mastering Email with Mutt: A Step-by-Step Guide to Replacing your email client on MacOS

Welcome to the first of our 24-article series, in which you will discover the power of the terminal and how it can replace many of the GUI tools you're used to. Imagine this: It's 6am and you've just woken up, time to check your email. Instead of reaching for your phone, you turn on your laptop. But this time, don't open your typical email client like Outlook or Apple Mail. Instead, launch the Terminal and follow our guide below to learn how to use Mutt, a powerful terminal-based email client.

What does this article replace?

This morning, we say goodbye to our reliance on your go to email client. This terminal-driven solution offers more customization, is less resource-hungry, and can provide a speedier and more streamlined email experience.

Prerequisite

  1. MacOS operating system (although this should work on any Unix based system)
  2. A Gmail email address e.g someone@gmail.com

How long will it take to set up?

Expect to spend around 1 hour getting this all setup. Once everything is set up, you'll see that the time investment is well worth it.

3 out of 5 stars

Difficulty Rating:

Exploring the world of terminal-based email comes with a moderate difficulty level of 3 out of 5. Setting up and managing your emails directly from the terminal requires a good understanding of email protocols and configuration. It provides a sense of efficiency and control, as you interact with your emails through the command line.

Step 1: Getting set up with Homebrew

To embark on this journey, you'll first need Homebrew, the trusty package manager that simplifies software installations on your Mac. If Homebrew isn't part of your software toolbox yet, let's get it with this command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Step 2: Installing Mutt

With Homebrew installed, we're all set to install Mutt. Installing it is a breeze thanks to Homebrew. Back in your terminal, execute:

brew install mutt

This command will ensure Mutt and all its dependencies are properly installed.

Step 3: Safekeeping your credentials with "pass"

To securely handle your email credentials, we'll employ pass, the standard Unix password manager. Let's install it with Homebrew:

brew install pass

Now, we initialize pass with your Gmail address:

pass init your-email@gmail.com

Next, store your Gmail password with pass:

pass insert Mutt/your-email

Here, replace "your-email" with the portion of your Gmail address that appears before "@gmail.com". For example, if your email is "someone@gmail.com", you would enter "someone".

Step 4: Configuring Mutt

Mutt needs some instructions on how to operate. We provide this through a .muttrc file in your home directory. Fire up your terminal text editor (vim, nano, emacs, or even ed if you're feeling brave) and get this configuration going.

Step 5: Unleashing Mutt's potential with .muttrc

To fully utilise Mutt with Gmail, we need to configure it with some Gmail-specific settings. Let's open the .muttrc file we created and add the following lines. Don't forget to replace your-email@gmail.com with your actual Gmail address:

set from = "your-email@gmail.com"
set realname = "Your Real Name"
set imap_user = "your-email@gmail.com"
set imap_pass = `pass Mutt/your-email`
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed="+[Gmail]/Drafts"
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates
set smtp_url = "smtp://your-email@gmail.com@smtp.gmail.com:587/"
set move = no
set imap_keepalive = 900
set smtp_pass = `pass Mutt/your-email`

These settings will configure Mutt to use Gmail's IMAP and SMTP servers, allowing you to retrieve and send emails through Gmail directly from your terminal. You'll also specify which Gmail folder to use for storing drafts.

Step 6: Kicking off Mutt

Finally, the moment you've been waiting for! Launch Mutt from the terminal:

mutt

You're now accessing your email right from the terminal, bringing a vintage charm to your modern MacOS.

Step 7: Sending your first Terminal email

Navigate your inbox using the arrow keys, and press m to compose a new email. If everything has been set up correctly, you'll be typing out an email in your terminal in no time.

Step 8: Reading your emails

With Mutt set up, you can view your emails with a simple command. From the Mutt interface, navigate your list of emails using the arrow keys. To open an email, simply hit Enter. You can scroll through the email with the arrow keys and exit back to your email list by hitting 'q'.

Step 9: Replying to an email

Replying to an email in Mutt is straightforward. With an email open, hit 'r' to reply. This will open a text editor where you can compose your response. Once you're done, save and exit the text editor to send your reply.

And there you have it: reading and replying to emails straight from the Terminal!


Troubleshooting: The SMTP Challenge

You might encounter an issue while sending an email: "No authenticators available". This issue arises due to authentication challenges with the SMTP server. In most cases, a simple fix is to add the following line in your .muttrc file:

set smtp_authenticators = 'gssapi:login'

And with that, you've embarked on a journey that very few dare to take! You've made email a unique, terminal-based experience, free from distracting GUI elements. This first hour in the terminal has been about mastering Mutt, but there are 23 more to go. Are you ready to see what else the terminal has to offer?


Extra: Creating a run-mutt.sh file

In some cases, pass may not work directly within the .muttrc file. To get around this, we can create a small script to set the password as an environment variable before running Mutt.

First, create a new file named run-mutt.sh:

touch run-mutt.sh

Open run-mutt.sh in your text editor and add the following lines:

#!/bin/sh
export IMAP_PASS=$(pass Mutt/your-email)
export SMTP_PASS=$(pass Mutt/your-email)
mutt

Don't forget to make your script executable:

chmod +x run-mutt.sh

Then modify your .muttrc file to use these environment variables for the IMAP and SMTP passwords:

set imap_pass = "$IMAP_PASS"
set smtp_pass = "$SMTP_PASS"

Finally, instead of running Mutt directly, run your new run-mutt.sh script:

./run-mutt.sh

This will ensure the correct passwords are passed to Mutt.

You can create an alias for ./run-mutt.sh in your bash or zsh profile so that you can invoke it with a memorable, simplified command.

Open your shell profile file. If you're using bash, this would typically be ~/.bash_profile or ~/.bashrc. For zsh users, it's ~/.zshrc. You can open the file with a text editor like nano or vim.

Once inside the file, add the following line to create the alias. In this example, we're using muttmail as our alias, but you can replace that with any command you find memorable:

alias muttmail='~/path/to/run-mutt.sh'

Replace ~/path/to/run-mutt.sh with the actual path to your run-mutt.sh script.

Save and close the file. Then, source your profile file to apply the changes with the source command. If you're using bash, the command might look like this:

source ~/.bash_profile

Or, for zsh:

source ~/.zshrc

Now, you can simply use the command muttmail to run your script! This alias will persist across terminal sessions, so you'll always have your memorable command handy.


With this extra bit of scripting wizardry, you've now got a robust solution for managing your email right from the terminal. Whether you're going all-in for a full 24 hours in the terminal or just dipping your toes into the world of command line applications, mastering Mutt is a great way to start the day. Happy emailing!