10

How to setup the email client Mutt to send, receive and read email under CentOS and Ubuntu using a Gmail account as a relay

21

Gmail Setup

For authentication, you'll have to do either of two things:

  1. Generate an application-specific password for your Google Account (your only option if you're using 2FA),
  2. Turn on less-secure app access (not an option with 2FA)

In gmail, go click the gear icon, go to Settings, go to the tab Forwarding POP/IMAP, and click the Configuration instructions link in IMAP Access row.

Then click I want to enable IMAP. At the bottom of the page, under the paragraph about configuring your mail client, select Other. Note the mail server information and use that information for further settings as shown in the next section.

Install mutt

CentOS

yum install mutt

Ubuntu

sudo apt-get install mutt

Configure Mutt

Create

mkdir -p ~/.mutt/cache/headers
mkdir ~/.mutt/cache/bodies
touch ~/.mutt/certificates

Create mutt configuration file muttrc

touch ~/.mutt/muttrc

Open muttrc

vim ~/.mutt/muttrc

Add following configurations

set ssl_starttls=yes
set ssl_force_tls=yes

set imap_user = "change_this_user_name@gmail.com"
set imap_pass = "PASSWORD"

set from="change_this_user_name@gmail.com"
set realname="Your Name"

set folder = "imaps://imap.gmail.com/"
set spoolfile = "imaps://imap.gmail.com/INBOX"
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 smtp_url = "smtps://change_this_user_name@gmail.com:PASSWORD@smtp.gmail.com:465/"

set move = no
set imap_keepalive = 900

Make appropriate changes, like change_this_user_name to your gmail user name and PASSWORD to your gmail password. And save the file.

Now you are ready to send, receive and read email using email client Mutt by simply typing mutt.

For the first time it will prompt to accept SSL certificates; press a to always accept these certificates.

Now you will be presented with your Gmail inbox.

  • 2
    This still works with Ubuntu and Gmail as of today, if anyone was wondering. – mkingsbu Sep 6 '16 at 19:45
  • 1
    Works with Gmail and mutt installed via brew on OSX High Sierra as well. Frankly this should work with any normal install of mutt. Thanks Sushant! – Venoda May 23 '18 at 12:59
  • 1
    Worked perfectly for me...the only thing I would add is that if you have 2fa enabled, you'll need to setup an application password. You can get to that in your google account settings under security. – Ricky Nelson Feb 10 at 17:59
  • After doing the above-mentioned steps. Mutt still says unable to reach imap.gmail.com. How can I narrow down the problem here? – Prathu Baronia Apr 27 at 19:46
  • 1
    @SushantMane I found the solution to my problem, it wasn't related to IMAP access settings. My university's network has blocked IMAP ports and hence mutt wasn't able to connect to imap.gmail.com. Everything worked fine after I switched to an external network. – Prathu Baronia Apr 29 at 13:58
0

a) Generate an APPLICATION-SPECIFIC PASSWORD from your Google Account

b01) Install Mutt Mail User Agent:

apt install mutt

b02) It ins't necessary to do any port forwarding, trigger or Virtual Server modification in your router!

b03) Generate directories as follows:

mkdir -p ~/.mutt/cache/headers

mkdir ~/.mutt/cache/bodies

touch ~/.mutt/certificates

b04) Use the following muttrc config:

nano muttrc on .mutt directory:

set from = "user@gmail.com"
set realname = "User Name"
set imap_user = "user@gmail.com"
set imap_pass = "pwd"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "imaps://imap.gmail.com/INBOX"
set postponed ="+[Gmail]/Drafts"
set header_cache =~/.mutt/cache/headers
set message_cachedir =~/.mutt/cache/bodies
set certificate_file =~/.mutt/certificates
set smtp_url = "smtps://user@gmail.com@smtp.gmail.com:465/"
set smtp_pass = "pwd"
set move = no
set imap_keepalive = 900

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.