How to setup the email client Mutt to send, receive and read email under CentOS and Ubuntu using a Gmail account as a relay
2 Answers
Gmail Setup
For authentication, you'll have to do either of two things:
- Generate an application-specific password for your Google Account (your only option if you're using 2FA),
- 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 = "[email protected]"
set imap_pass = "PASSWORD"
set from="[email protected]"
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://[email protected]:[email protected]: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.
- 69,900
- 13
- 192
- 292
- 519
- 1
- 4
- 10
-
2This still works with Ubuntu and Gmail as of today, if anyone was wondering. – mkingsbu Sep 06 '16 at 19:45
-
1Works 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! – Shoddy Weather May 23 '18 at 12:59
-
1Worked 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 '19 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 '19 at 19:46
-
@Prathu Please enable IMAP access, under Gmail settings. – Sushant Mane Apr 28 '19 at 22:19
-
2@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 '19 at 13:58
-
In case you don't want to store your password in the `muttrc` file, you can simply omit the line `set imap_pass = "PASSWORD"` in the configuration file listed above and also write `set smtp_url = "smtps://[email protected]@smtp.gmail.com:465/"`, mutt will prompt you to enter the password for receiving and sending emails – Alf Jul 04 '19 at 22:06
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 = "[email protected]"
set realname = "User Name"
set imap_user = "[email protected]"
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://[email protected]@smtp.gmail.com:465/"
set smtp_pass = "pwd"
set move = no
set imap_keepalive = 900
- 698
- 7
- 29