Skip to main content

Gmail Setup

Gmail Setup for NeoMutt

This guide covers configuring NeoMutt to send and receive emails using a Gmail account via IMAP and SMTP, including Google Account security setup, GPG password encryption, and sidebar configuration.


1. Prerequisites & Google Account Configuration

Modern Gmail requires two-factor authentication (2FA) and an App Password for IMAP/SMTP client access. Direct password authentication is blocked by Google.

  1. Enable 2-Step Verification:

    • Go to Google Account Security.
    • Under "How you sign in to Google", turn on 2-Step Verification if not already enabled.
  2. Generate an App Password:

    • Navigate to App Passwords.
    • Enter a custom app name (e.g., NeoMutt).
    • Record the generated 16-character password (e.g. abcd efgh ijkl mnop).
  3. Enable IMAP in Gmail:

    • Open Gmail in your browser -> Settings (gear icon) -> See all settings.
    • Go to the Forwarding and POP/IMAP tab.
    • Select Enable IMAP.
    • Click Save Changes.

2. Securely Encrypt Your Password with GPG

Run gpg interactively to encrypt your App Password directly to a .gpg file:

gpg -e -r "your.email@gmail.com" -o ~/.config/neomutt/gmail_pass.gpg
  1. Run the command above.
  2. Paste or type your 16-character App Password.
  3. Press Enter, then press Ctrl+D (EOF) to save and finish.

3. Configuration (~/.config/neomutt/neomuttrc)

Create ~/.config/neomutt/neomuttrc. The imap_pass and smtp_pass settings dynamically decrypt the GPG file at runtime:

# ==============================================================================
# Identity & Account Settings
# ==============================================================================
set realname = "Your Full Name"
set from = "your.email@gmail.com"
set use_from = yes

# Authentication (Dynamically decrypt password via GPG)
set imap_user = "your.email@gmail.com"
set imap_pass = `gpg --batch --quiet --decrypt ~/.config/neomutt/gmail_pass.gpg`

# IMAP Server Settings
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed = "+[Gmail]/Drafts"
set record = "+[Gmail]/Sent Mail"
set trash = "+[Gmail]/Trash"

# SMTP Server Settings (Sending Mail)
set smtp_url = "smtps://your.email@gmail.com@smtp.gmail.com:465/"
set smtp_pass = `gpg --batch --quiet --decrypt ~/.config/neomutt/gmail_pass.gpg`

# Mailboxes for NeoMutt Sidebar
named-mailboxes "Inbox"      "+INBOX"
named-mailboxes "Sent"       "+[Gmail]/Sent Mail"
named-mailboxes "Drafts"     "+[Gmail]/Drafts"
named-mailboxes "All Mail"   "+[Gmail]/All Mail"
named-mailboxes "Spam"       "+[Gmail]/Spam"
named-mailboxes "Trash"      "+[Gmail]/Trash"

# ==============================================================================
# NeoMutt Sidebar Settings
# ==============================================================================
set sidebar_visible = yes
set sidebar_width = 24
set sidebar_short_path = yes
set sidebar_next_new_wrap = yes
set sidebar_format = "%D%?Z? [%Z]?%* %?N?%N/?"

# Sidebar Navigation Keybindings
bind index,pager \Cp sidebar-prev           # Ctrl+p: Previous folder
bind index,pager \Cn sidebar-next           # Ctrl+n: Next folder
bind index,pager \Co sidebar-open           # Ctrl+o: Open folder
bind index,pager B sidebar-toggle-visible  # B: Toggle sidebar visibility

# ==============================================================================
# Cache & Performance
# ==============================================================================
set header_cache = "~/.cache/neomutt/headers"
set message_cachedir = "~/.cache/neomutt/bodies"
set certificate_file = "~/.config/neomutt/certificates"

# Connection & Sync Settings
set move = no                  # Do not auto-move read messages
set imap_keepalive = 900       # Keep IMAP connection active
set mail_check = 60            # Poll for new mail every 60s
set timeout = 10               # Idle timeout before checking mail

# ==============================================================================
# UI & Threading Settings
# ==============================================================================
set sort = threads             # Thread conversation view
set sort_aux = reverse-last-date-received
set sort_re = yes

4. Usage & Verification

  1. Launch NeoMutt:
    neomutt
    
  2. Sidebar Navigation:
    • Ctrl+n / Ctrl+p: Move cursor down/up through mailboxes in sidebar.
    • Ctrl+o: Select and switch to the highlighted sidebar folder.
    • B: Toggle sidebar visibility on/off.
  3. Send Test Email: Press m in index view to compose and send a message.