CLI all the things!
I have always wanted to use mutt to connect to my Gmail account. The biggest blocker for me has always been that most tutorials are missing that last 10% that I need to get up and running. Well the other day I got it running finally and I wanted to throw this up in case someone else is running into the same issues that I was having. There may be extra settings in the conf files, I didn’t take time to minimize I’m just posting what I have working.
1.) Setup Application password
When it comes to my gmail account I like to enable 2-step authentication. This can create a bit of an issue for command line clients as they usually aren’t built to support 2-step auth natively. Enter application passwords. These work like most authentication tokens so when you generate the password don’t leave it laying around. You should be able to generate your app passwords HERE but if the url has changed then just google around. You should get a 16 digit password out of this.
2.) Install Mutt
On Ubuntu execute the following command:
$ sudo apt-get install mutt
After installing mutt create the default folders and cert file:
mkdir -p ~/.mutt/cache touch ~/.mutt/certificates
After this you will have to create your muttrc file, located at ~/.muttrc. You will have to paste in your application password into the appropriate places:
set imap_user = 'email@example.com' set imap_pass = 'applicationpassword' set sendmail="/usr/sbin/ssmtp" set folder="imaps://imap.gmail.com" set spoolfile="imaps://imap.gmail.com/INBOX" set record="imaps://imap.gmail.com/[Gmail]/Sent Mail" set postponed="imaps://imap.gmail.com/[Gmail]/Drafts" set header_cache = "~/.mutt/cache/headers" set message_cachedir = "~/.mutt/cache/bodies" set certificate_file = "~/.mutt/certificates" set from = 'firstname.lastname@example.org' set realname = 'Your Name' set smtp_url = 'smtp://email@example.com:587/' set smtp_pass='aplication' set move = no set imap_keepalive = 900 # Gmail-style keyboard shortcuts macro index,pager ga "<change-folder>=[Gmail]/All<tab><enter>" "Go to all mail" macro index,pager gi "<change-folder>=INBOX<enter>" "Go to inbox" macro index,pager gs "<change-folder>=[Gmail]/Starred<enter>" "Go to starred messages" macro index,pager gd "<change-folder>=[Gmail]/Drafts<enter>" "Go to drafts" macro index,pager e "<enter-command>unset trash\n <delete-message>" "Gmail archive message" # different from Gmail, but wanted to keep "y" to show folders.
Replace the fields that say ‘applicationpassword’ with your actual 16 digit password. You will also notice that there are some keybindings to give gmail like shortcuts for navigating around your inboxes like ‘gi’. At this point you should just have to launch Mutt and you should be able to start reading your emails from the command line:
3.) Send emails with SSMTP
Now you will have to install SSMTP if you want to be able to send emails from Mutt. Start by installing SSMTP:
$ sudo apt-get install ssmtp
firstname.lastname@example.org mailhub=smtp.gmail.com:587 AuthUseremail@example.com AuthPass=applicationpass UseTLS=YES UseSTARTTLS=YES firstname.lastname@example.org rewriteDomain=gmail.com FromLineOverride=YES
Make sure you update the file to reflect your application password. Next edit /etc/ssmtp/revaliasses:
You should now be able to launch mutt and send a message; type ‘m’ and a little ‘to:’ prompt should come up at the bottom. Hope you get some use out of this!