Gmail from Old Dog Terminal

Gmail from Old Dog Terminal

Mutt is used to send and receive email from your terminal, even if you're using hosted service such as Gmail.

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 back in simpler times, when checking email was a call to?uucp?and a glance at?/var/mail. However, it's adapted nicely 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.

In this article I am going to guide you through how to configure mutt for Gmail so that you can use Gmail right from the old dog terminal. So without wasting any time let's directly dive in...

No alt text provided for this image

Install Mutt

On Linux, you can install Mutt from your distribution's software repository and then create a?.mutt?directory to hold its configuration files:

$ sudo dnf install mut
$ mkdir ~/.muttt        

Mutt is a mail user agent (MUA), meaning its job is to read, compose, and send email to an outbound mail spool. It's the job of some other application or service to actually transfer a message to or from a mail server (although there's a lot of integration with Mutt so that it seems like it's doing all the work even when it's not.) Understanding this separation of tasks can help configuration make a little more sense.

It also explains why you must have helper applications (in addition to Mutt) depending on what service you need to communicate with. For this article, I use IMAP so that my local copy of email and my email provider's remote copy of mail remain synchronized. Should you decide to use POP instead, that configuration is even easier to configure and can be done without any external tools. IMAP integration, however, requires OfflineIMAP, a Python application available from?its GitHub repository.

Eventually, you'll be able to install it with the?python3 -m pip?command, but as of this writing, you must install OfflineIMAP manually because it's still being ported from Python 2 to Python 3.

OfflineIMAP requires?imaplib2, which is also in heavy development, so I prefer doing a manual install of that, as well. The process is the same: clone the source code repository with Git, change into the directory, and install with?pip.

First, install the?rfc6555?dependency:

$ python3 -m pip install --user rfc6555        

Next, install?imaplib2?from source:

$ git clone [email protected]:jazzband/imaplib2.gi
$ pushd imaplib2.git
$ python3 -m pip install --upgrade --user .
$ popdt        

Finally, install OfflineIMAP from source:

$ git clone [email protected]:OfflineIMAP/offlineimap3.gi
$ pushd offlineimap3.git
$ python3 -m pip install --upgrade --user .
$ popdt        

Configure OfflineIMAP

OfflineIMAP reads the configuration file?~/.offlineimaprc?by default. A template for this file, named?offlineimap.conf, is included in the Git repository you cloned to install OfflineIMAP. Move the example file to your home directory:

$ mv offlineimap3.git/offlineimap.conf ~/.offlineimaprc        

Open the file in your favorite text editor and read through it. It's a well-commented file, and it's good to get familiar with the options available.

Here's 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 end product ought to look like:

[general
ui = ttyui
accounts = %your-gmail-username%
pythonfile = ~/.mutt/password_prompt.py
fsync = False

[Account %your-gmail-username%]
localrepository = %your-gmail-username%-Local
remoterepository = %your-gmail-username%-Remote
status_backend = sqlite
postsynchook = notmuch new

[Repository %your-gmail-username%-Local]
type = Maildir
localfolders = ~/.mail/%your-gmail-username%-gmail.com
nametrans = lambda folder: {'drafts':  '[Gmail]/Drafts',
                            'sent':    '[Gmail]/Sent Mail',
                            'flagged': '[Gmail]/Starred',
                            'trash':   '[Gmail]/Trash',
                            'archive': '[Gmail]/All Mail',
                            }.get(folder, folder)

[Repository %your-gmail-username%-Remote]
maxconnections = 1
type = Gmail
remoteuser = %your-gmail-username%@gmail.com
remotepasseval = '%your-gmail-API-password%'
## remotepasseval = get_api_pass()
sslcacertfile = /etc/ssl/certs/ca-bundle.crt
realdelete = no
nametrans = lambda folder: {'[Gmail]/Drafts':    'drafts',
                            '[Gmail]/Sent Mail': 'sent',
                            '[Gmail]/Starred':   'flagged',
                            '[Gmail]/Trash':     'trash',
                            '[Gmail]/All Mail':  'archive',
                            }.get(folder, folder)
folderfilter = lambda folder: folder not in ['[Gmail]/Trash',
                                             '[Gmail]/Important',
                                             '[Gmail]/Spam',
                                             ]]        

There are two replaceable values in this file:?%your-gmail-username%?and?%your-gmail-API-password%. Replace the first with your Gmail user name. That's the part of your email address on the left of [email protected]?part. You must acquire the second value from Google through a two-factor authentication (2FA) setup process (even though you don't need to use 2FA to check email).

Set up 2FA for Gmail

Google expects its users to use the Gmail website for email, so when you attempt to access your email outside of Gmail's interface, you're essentially doing so as a developer (even if you don't consider yourself a developer). In other words, you're creating what Google considers an "app." To obtain a developer-level?app password,?you must set up 2FA; through that process, you get an app password, which Mutt can use to log in outside the usual browser interface.

For safety, you can also add a recovery email address. To do that, go to Google's?Account Security page?and scroll down to?Recovery email.

To set up 2FA, go back to the Account Security page, and click on?2-step Verification?to activate and configure it. 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 it and paste it into your?.offlineimaprc?file in the place of the?%your-gmail-API-password%?value.

Placing your API password in your?.offlineimaprc?file stores it in plain text, which can be dangerous. For a long while, I did this and felt fine about it because my home directory is encrypted. However, in the interest of better security, I now encrypt my API password with GnuPG. That's somewhat beyond the scope of this article


Enable IMAP in Gmail

There's one last thing before you can say goodbye to the Gmail web interface forever: You must enable IMAP access to your Gmail account.

To do this, go to the Gmail web interface, click the "cog" icon in the upper-right corner, and select?See all settings. In Gmail?Settings, click the?POP/IMAP?tab, and enable the radio button next to?Enable IMAP. Save your settings.

Now Gmail is configured to give you access to your email outside a web browser.

Configure Mutt

Now that you're all set up for Mutt, you'll be happy to learn 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 sake of Simplicity my mutt config looks like this:

set ssl_starttls=ye
set ssl_force_tls=yes

set from='[email protected]'
set realname='Tux Example'

set folder = imaps://imap.gmail.com/
set spoolfile = imaps://imap.gmail.com/INBOX
set postponed="imaps://imap.gmail.com/[Gmail]/Drafts"
set smtp_url="smtp://smtp.gmail.com:25"
set move = no
set imap_keepalive = 900
set record="imaps://imap.gmail.com/[Gmail]/Sent Mail"

# Paths 
set folder           = ~/.mail
set alias_file       = ~/.mutt/alias
set header_cache     = "~/.mutt/cache/headers"
set message_cachedir = "~/.mutt/cache/bodies"
set certificate_file = ~/.mutt/certificates
set mailcap_path     = ~/.mutt/mailcap
set tmpdir           = ~/.mutt/temp
set signature        = ~/.mutt/sig
set sig_on_top       = yes

# Basic Options
set wait_key = no
set mbox_type = Maildir
unset move               # gmail does that

# Sidebar Patch
set sidebar_visible = yes
set sidebar_width   = 16
color sidebar_new color221 color233

## Account Settings
# Default inbox
set spoolfile = "+example.com/INBOX"

# Mailboxes to show in the sidebar.
mailboxes +INBOX \
          +sent \
          +drafts

# Other special folder
set postponed = "+example.com/drafts"

# navigation
macro index gi "<change-folder>=example.com/INBOX<enter>" "Go to inbox"
macro index gt "<change-folder>=example.com/sent" "View sent"s        

Nothing in this file requires changing, but consider replacing the fake name?Tux Example?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 Mutt

Before launching Mutt, run?offlineimap?from a terminal to sync your computer with the remote server. The first run of this may take?a long time, so leave it running.

Once your account has synchronized, you can launch Mutt:

$ mutt        

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

Conclusion

Learning Mutt is a mixture of exploring the application and finding your favorite hacks for your .muttrc config. For example, my config file integrates Emacs for composing messages, LDAP so that I can search through contacts, GnuPG so that I can encrypt and decrypt messages, link harvesting, HTML views, and much more. You can make Mutt anything you want it to be (as long as you want it to be an email client), and the more you experiment, the more you discover.


So That's It from my side for now till then feel free to check out other write-ups by visiting to my profile and feel free to reach out in case of collaboration or need any assistance.


Thanks

- SK -


Author


要查看或添加评论,请登录

SAKSHAM TRIVEDI的更多文章

  • DNF5... It's time to rethink the package management.

    DNF5... It's time to rethink the package management.

    Hello Folks, It's been a while since I have written any article. Well here I am now.

  • File BackuP & Sync...

    File BackuP & Sync...

    Introduction In today's fast-paced world, seamless file sharing and synchronization are essential for efficient…

  • Simplifying SSH Connection: A Guide To Build Your Own Proxy Network

    Simplifying SSH Connection: A Guide To Build Your Own Proxy Network

    Establishing a secure SSH connection between Machine A and Machine F can be challenging, especially when intermediate…

  • Unleashing the Power of Linux: A Browser-Based Linux Experience

    Unleashing the Power of Linux: A Browser-Based Linux Experience

    To access Fedora Linux's graphical system in a browser using Apache Guacamole, you will need to set up Guacamole on a…

  • Let's WhatsApp using Bash

    Let's WhatsApp using Bash

    S: AuthorAuthorIntroduction In today's fast-paced world, automation plays a crucial role in streamlining various tasks.…

    6 条评论
  • Ping... a message arrrived

    Ping... a message arrrived

    In this short tutorial, Here I am going to demonstrate chatting using ping command. For this first of all you need a…

    1 条评论
  • Containerized SSH Server

    Containerized SSH Server

    In this article I am going to demonstrate how to containerize SSH server so without any further explanation let's…

  • Mutiple Linux shells on a same system

    Mutiple Linux shells on a same system

    Recently I came across the question is there any possibility that multiple shells can be installed on the same system…

  • Jupyter Lab as a container

    Jupyter Lab as a container

    This article is focused on containerizing Jupyter Notebook inside the docker container with a fully-fledged develop…

  • Launching graphical application inside the docker container

    Launching graphical application inside the docker container

    Hello guys, In this article I am going to discuss how to launch the graphical application inside the docker. So, for…

社区洞察

其他会员也浏览了