mutt is a console/terminal base Email client. it is fast and flexible with many option for customization. It works well with any editor of choice. Vim, emacs and neovim are common editor that are used in mutt for composing and replying to email.
Gmail despite a wonderful webui but lack the flexibility to manipulate email using key binding. Fortunely, Gmail does provides imap service to allow the usage of email services from third party email client. Console Email client (mutt) is an excellent alternative to read Email from console/terminal.
- Install mutt and downlad mutt_oauth2.py script
- Enable Gmail imap service with Oauth2
- Configure mutt
fedora/redhat distribution
sudo dnf install mutt
debian/ubuntu distriution
sudo apt install mutt
Download Mutt Oauth2 scripts. Follow the instruction to populate the client id and client secret in the mutt_oauth2.py. Run the script with --authorize flag to obtain the refresh token.
Login to Google cloud.
-
Create a new project if no project exist.
-
Select "Oauth Consent screen"
-
Create User Type - "External"
-
Provide detail for "App Name", "User support email", "Developer contact". The rest of the field can be left empty.
-
Add the following three scope manaully:
Gmail API - https://www.googleapis.com/auth/gmail.modify Google Drive API - https://www.googleapis.com/auth/drive.appdata People API - https://www.googleapis.com/auth/contacts.readonly
-
Enable the API access of the various scope using the following links.
Gmail - https://console.developers.google.com/apis/api/gmail.googleapis.com/overview Google Drive API https://console.developers.google.com/apis/api/drive.googleapis.com/overview People API - https://console.developers.google.com/apis/api/people.googleapis.com/overview
-
Finally add a user and complete the creation of "Oauth consent screen"
-
Select "Credentials". Create new credential for Oauth2 Client ID.
-
Create a credntial for "Desktop app" providing the app with a new name.
-
Note the "Client ID" and "Client Secret". This will be needed to populate the mutt_oauth2.py script under the Google registration field.
Run the following command
mutt_oauth2.py gmail.tokens --verbose --authorize
Test the token to ensure the token is correct and working
mutt_oauth2.py gmail.tokens --verbose --test
Add the following snipplet in muttrc to start using mutt with Gmail.
set realname = "<Real name>"
set from = "name <gmail id>"
set use_from = yes
set envelope_from = yes
set smtp_url = "smtps://<gmail id>@smtp.gmail.com:465/"
set imap_user = "<gmail id>"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed ="+[Gmail]/Drafts"
set trash = "+[Gmail]/Trash"
set ssl_force_tls = yes
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates
set imap_check_subscribed
set imap_keepalive = 100
unset imap_passive
set mail_check = 60
set imap_authenticators="oauthbearer:xoauth2"
set imap_oauth_refresh_command="/path/to/mutt_oauth2.py /path/of/tokens/file.token"
set smtp_authenticators=${imap_authenticators}
set smtp_oauth_refresh_command=${imap_oauth_refresh_command}