Send and receive Gmail from the Linux command line | Opensource.com

I am a mutt user. i like to view and compose emails in the comfort of my linux terminal. With a thin, minimal client like mutt, I know I can have my email available regardless of system specs or internet access. and because I have a linux terminal open most of the time, my email client has essentially no footprint on my desktop space. it’s hidden in a terminal tab or multiplexer panel, so I can ignore it when I don’t need it, but quickly access it when I need it.

A commonly perceived problem with mutt is that most of us use hosted email accounts these days and interact with actual email protocols only superficially. mutt (and elm before it) was created in simpler times, when checking email was a call to uucp and a look at /var/mail. however, it adapts very well to developing technology and works well with all sorts of modern protocols like pop, imap, and even ldap, so you can use mutt even if you’re using gmail as your email host.

Because it’s relatively rare to run your own email server these days, and because gmail is so common, this tutorial assumes you’re using mutt with gmail. If you’re concerned about email privacy, consider opening an account with ProtonMail or Tutanota, both of which provide fully encrypted email. tutanota has many open source components, and protonmail provides an imap bridge for paid users so you don’t have to work to access your email outside of a browser. However, many businesses, schools, and organizations don’t run their own email services and only use Gmail, so you can have a Gmail account whether you want it or not.

If you’re running your own email server, configuring mutt is even easier than I demonstrate in this article, so just dive in.

install mutt

on linux, you can install mutt from your distribution’s software repository and then create a .mutt directory to store your configuration files:

on macos, use macports or homebrew. on windows, use chocolate.

mutt is a mail user agent (mua), which means its job is to read, compose, and send email to an outgoing mail queue. it’s the job of some other application or service to transfer a message to or from a mail server (although there’s a lot of integration with mutt, so it looks like it’s doing all the work, even when it’s not). understanding this separation of duties can help the configuration make a bit more sense.

See Also:  Mail2web

also explains why you should have helpers (in addition to mutt) depending on which service you need to communicate with. For this article, I use imap so that my local copy of email and the remote copy of email from my email provider stay in sync. if you decide to use pop instead, that setup is even easier to configure and can be done without any external tools. however, imap integration requires offlineimap, a python application available in its github repository.

Eventually, you will be able to install it with the python3 -m pip command, but at the time of writing, you need to install offlineimap manually because you are still porting from python 2 to python 3.

offlineimap requires imaplib2, which is also under heavy development, so I prefer to do a manual install of that as well. the process is the same: clone the source code repository with git, change to the directory and install with pip.

first, install the rfc6555 dependency:

then install imaplib2 from source:

finally, install offlineimap from source:

if you are using cygwin on windows, you must also install portalocker.

configure offline map

offlineimap reads the ~/.offlineimaprc configuration file by default. A template for this file, called offlineimap.conf, is included in the git repository that you cloned to install offlineimap. move the example file to your home directory:

Open the file in your favorite text editor and read it. it’s a well-commented file and it’s good to familiarize yourself with the available options.

here is my .offlineimaprc as an example, with comments removed for brevity. some values ​​may be slightly different for you, but this gives you a reasonable idea of ​​what your final product should look like:

See Also:  Bugsnax - All Mail Quests Completion Guide - Riot Bits

There are two replaceable values ​​in this file: %your-gmail-username% and %your-gmail-api-password%. replace the first one with your gmail username. that’s the part of your email address to the left of the @gmail.com part. you need to acquire the second value from google through a two-factor authentication (2fa) setup process (although you don’t need to use 2fa to check email).

configure 2fa for gmail

google expects its users to use the gmail website for email, so when you try to access your email outside of the gmail interface, you’re basically doing it as a developer (even if you don’t consider yourself a developer). ). In other words, you’re creating what Google considers an “app”. to get a developer level app password, you need to set up 2fa; through that process, you get an app password, which mutt can use to log in outside of the usual browser interface.

For security, you can also add a recovery email address. To do this, go to the google account security page and scroll down to recovery email.

To set up 2fa, go back to the account security page and click 2-Step Verification to turn it on and set it up. this requires a mobile phone for setup.

After activating 2fa, you get a new google account security option: app passwords. click on it to create a new app password for mutt. google generates the password for you, so copy and paste it into your .offlineimaprc file in place of the %your-gmail-api-password% value.

Putting your api password in your .offlineimaprc file stores it in plain text, which can be dangerous. for a long time i did this and i felt good because my home directory is encrypted. however, for the sake of better security, I now encrypt my api password with gnupg. that’s beyond the scope of this article, but I’ve written an article that demonstrates how to configure gpg password integration.

enable imap in gmail

There is one last thing before you can say goodbye to the gmail web interface forever: you need to enable imap access to your gmail account.

See Also:  Why a Free Satanic Bible is Unsatanic - Church of Satan

To do this, go to the gmail web interface, click the “gear” icon in the upper right corner and select view all settings. in gmail settings, click the pop/imap tab and enable the radio button next to enable imap. save your settings.

gmail is now configured to give you access to your email outside of a web browser.

configure mutt

Now that you’re all set for mutt, you’ll be glad to know that configuring mutt is the easy part. As with .bashrc, .zshrc, and .emacs files, there are many examples of very good .muttrc files available on the internet. For my config file, I borrowed options and ideas from kyle rankin, paul frields, and many others, so I’ve abbreviated my .muttrc file to just the bare essentials for the sake of simplicity:

You don’t need to change anything in this file, but consider replacing the fake name example tux and the fake address example.com with something that applies to you. copy and paste this text into a file and save it as ~/.mutt/muttrc.

launch mongrel

Before running mutt, run offlineimap from a terminal to sync your computer with the remote server. the first run of this takes a long time, so let it run overnight.

once your account has synced, you can run mutt:

mutt asks you for permission to create the directories it needs to organize your email activity, and then displays a view of your inbox.

learn dog

learning mutt is a mix of exploring the application and finding your favorite tricks for your .muttrc setup. for example, my config file integrates emacs to compose messages, ldap so you can search through contacts, gnupg so you can encrypt and decrypt messages, link harvesting, html views, and much more. you can make mutt whatever you want it to be (as long as you want it to be an email client), and the more you experiment, the more you’ll discover.

Leave a Reply

Your email address will not be published. Required fields are marked *