Mutt with Gmail on ubuntu

ಚಿರಾಗ್ ನಟರಾಜ್ mailinglist at chiraag.me
Thu Apr 22 21:44:54 UTC 2021


12021/02/31 07:22.37 ನಲ್ಲಿ, "M.R.P. zensky" <wintermute24x7 at icloud.com> ಬರೆದರು:
> 
> Hello does anyone know what the best way to configure mutt to work with gmail on ubuntu?

It depends entirely on what you would like your setup to be.

Personally, I set it up so that I download a copy of all of my emails using fetchmail. I use mutt for reading those maildirs and sending emails. Here are the directions for that setup:

First, I stick the following into ~/.config/fetchmail/fetchmailrc

--------------------------------------------------------------------------------
set postmaster "$username"
set bouncemail
set no spambounce
set softbounce
set properties ""
poll imap.gmail.com with proto IMAP
       user '$email' there with password '$password' is '$username' here
       options keep ssl sslproto 'TLS1+' mda "notmuch insert --keep --folder=$subdir/"
  folder "[Gmail]/All Mail"
--------------------------------------------------------------------------------

$email is your email address (including the '@gmail.com' part)
$password is the password used for logging on to your email (see note below if you use two-factor authentication, *which you should be doing*)
$username is your username on your computer
$subdir is a subdirectory for this account below your main "email" directory

A couple of notes:

1. If you have two-factor authentication enabled, you will have to generate an "app-specific password' or whatever it's called - you can find the steps for doing so here: https://support.google.com/accounts/answer/185833?hl=en
2. I use (and highly recommend!) notmuch as my "MDA" (which actually writes the email to disk). notmuch keeps an index of your email and enables really useful searching/tagging capabilities and I highly recommend it. If you use notmuch, $subdir is a directory below the database path. If you use another MDA (e.g. procmail or getmail_maildir), then $subdir should be the full path to the mailbox
3. I would encrypt this file if possible. I use gpg and encrypt the file to a keypair I have generated, but you can encrypt using "symmetric" (passphrase) encryption if you don't want to deal with managing private keys. If you do this (like I do), then the actual file is ~/.config/fetchmail/fetchmailrc.gpg. Then, you can start fetchmail like this: gpg -d -o - ~/.config/fetchmail/fetchmailrc.gpg | firejail fetchmail -s -d 5 -N -f -

In terms of mutt config, I split it up into a common config (~/.config/mutt/muttrc/muttrc.local) and then a mailbox-specific config (~/.config/mutt/muttrc/muttrc.local<x>, where <x> is a "code" for the specific mailbox).

I put the following into ~/.config/mutt/muttrc/muttrc.local<x> (which is the account-specific config):

--------------------------------------------------------------------------------
set spoolfile="$subdir"

set smtp_url="smtps://$email@smtp.gmail.com/"
set from="$name <$email>"
set realname="$name"
set imap_user=$email
set record="^"

set signature="~/.config/mutt/signatures/signature.<x>"
set header_cache=/home/chiraag/.cache/mutt/mutt_cache.<x>

send-hook . "source 'gpg -d ~/.config/mutt/mutt_secure/<x>.password.gpg |'"

source ~/.config/mutt/muttrc/muttrc.macros
source ~/.config/mutt/muttrc/muttrc.autocrypt
--------------------------------------------------------------------------------

A few notes:

1. When you type in your $email for smtp_url, you have to *escape* the @. So, for example, I would put mailinglist\@chiraag.me, so the full line would look like: set smtp_url="smtps://mailinglist\@chiraag.me@smtp.gmail.com/"
2. I store the account password (the app password from before, if you're using two-factor authentication) in an encrypted file and decrypt it on-demand when I start composing a new email (that's what that send-hook does).


I know this is a *lot* of information, but I've been successfully juggling several email accounts this way for a while now. I did *not* include my common config (muttrc.local) because it's a *lot* and most of it is cosmetic or heavily personalized. Let me know if you have questions!

Sincerely,

Chiraag
-- 
ಚಿರಾಗ್ ನಟರಾಜ್
Pronouns: he/him/his
-------------- next part --------------
A non-text attachment was scrubbed...
Name: publickey - mailinglist at chiraag.me - b0c8d720.asc
Type: application/pgp-keys
Size: 659 bytes
Desc: not available
URL: <http://lists.mutt.org/pipermail/mutt-users/attachments/20210422/35c391aa/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 233 bytes
Desc: OpenPGP digital signature
URL: <http://lists.mutt.org/pipermail/mutt-users/attachments/20210422/35c391aa/attachment.asc>


More information about the Mutt-users mailing list