Mutt using Gmail

Using Muttt with Gmail - a Howto

Keywords: mutt gmail command line cli

If necessary configure Gmail for multi-factor authentication:
Go to Gmail main page.
Click the Google Apps matrix next to your avatar at the top right.
Click 'Account' in the selection box. It's usually the top left.
Click 'Security'on the left
Scroll down to 'How you sign in to Google'.
Enable '2-step verification'

Get an 'app password':
Instructions found online may be incorrect. Try this:
https: //myaccount.google.com /apppasswords <=== remove the spaces
In the 'App name' field type mutt, then click 'create'.
You should get a 16 letter pass-code, unhelpfully with spaces.
Copy and paste the code to somewhere secure. Remove the spaces.

Install Mutt:
# pkg install mutt

Configure Mutt:
I added this section to the top of the muttrc file. There are several places this can be[1].
Act with caution, it contains you app specific Gmail password in plain text (eeek):

set imap_user = "<your_email>@gmail.com"
set imap_pass = "<pass-code here>"
set smtp_url = "smtp://<your_email>@smtp.gmail.com:587/"
set smtp_pass = $imap_pass
set from = "<your_email>@gmail.com"
set realname = "John Doe"
set ssl_starttls=yes
set ssl_force_tls=yes
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 mbox="imaps://imap.gmail.com/[Gmail]/All Mail"

Configure FreeBSD:
edit /etc/rc.conf - add:
sendmail_enable=none

Send test email:
Create a small text file called testemailtext.txt. The space after the title and before the target email address is important.
mutt -s "mutt testemail" <your_email>@gmail.com < testemailtext.txt

Test attachment:
mutt -s "test email with attachment" -a /tmp/cat_pic.png -- <your_email>@gmail.com < testemailtext.txt

great success

[1] I use ~/.muttrc
 
Last edited:
What a coincidence, I just had this idea to try out mutt and set it up to work with my gmail account. Your post comes at the right time for me and it is mos handy!
 
I also use Mutt with Gmail. Perhaps someone will be interested my muttrc :
Code:
set charset      = "utf-8"
set send_charset = "utf-8"
set signature    = "~/.mutt/signature"

# Mailcap ---------------------------------------------
set mailcap_path = ~/.mutt/mailcap
auto_view text/html
alternative_order text/html text/plain text/enriched
bind attach <return> view-mailcap

# Gmail -----------------------------------------------
set imap_user        = "<your_email>@gmail.com"
set imap_pass        = "<pass-code here>"
set smtp_url         = "smtp://<your_email>@gmail.com@smtp.gmail.com:587/
set smtp_pass        = "<pass-code here>"
set from             = "<your_email>@gmail.com"
set realname         = "<Myname>"
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 move             = no
set copy             = no
set sort             = 'threads'
set sort_aux         = 'last-date-received'
set ssl_starttls     = yes
set imap_check_subscribed

# Etc -------------------------------------------------
set mail_check = 30
set imap_keepalive = 900
set editor = 'vim + -c "set textwidth=60" -c "set wrap"'
set smtp_authenticators = 'gssapi:login'

# Colors ----------------------------------------------
# Make the foreground color of messages black and their
# # background the same color as the terminal background
color normal     white default

color hdrdefault cyan default
color attachment yellow default

color header     brightyellow default "From: "
color header     brightyellow default "Subject: "
color header     brightyellow default "Date: "

color quoted     green        default
color quoted1    cyan         default
color quoted2    green        default
color quoted3    cyan         default


color error      red          default       # error messages
color message    white        default       # message  informational messages
color indicator  brightwhite  blue          # indicator for the "current message"
color status     cyan         default       # status lines in the folder index
                                            # sed for the mini-help line
color tree       red          default       # the "tree" display of threads
                                            # within the folder index
color search     white        blue          # search matches found with search
                                            # within the internal pager
color markers    red          default       # The markers indicate a wrapped
                                            # line hen showing messages with looong lines
color index      yellow       default  '~O'
color index      yellow       default  '~N'
color index      brightred    default  '~F' # Flagged Messages are important!
color index      blue         default  '~D' # Deleted Mails - use dark color
                                            # as these are already "dealt with"

set query_command="abook --mutt-query '%s'" # Use abook with Mutt
macro index a     "|abook --add-email\n" 'add sender to abook'
macro pager a     "|abook --add-email\n" 'add sender to abook'
 
Back
Top