This is a guide to setting up access to email from a Gmail account (eg: @gmail.com) within Emacs (Doom Emacs) using notmuch
(a) and lieer
(a).
You may have to complete additional steps if you are not using doom emacs
(a) or if your set-up differs from mine in other ways.
Prerequisites
Please be sure you’ve completed these steps before continuing:
Required Software
lieer
git clone https://github.com/gauteh/lieer.git cd lieer pip3 install -r requirements.txt
notmuch
sudo apt install notmuch
Create an OAuth2 Client ID
- Please refer to: Create an OAuth2 Client ID
- Ensure GMail APIs are enabled for this Client ID.
- Download the JSON format of this key.
Enable notmuch
within emacs
This is written for those using doom emacs
(a). Those using other flavors of emacs
will need to enable notmuch
on their own.
- Enable
notmuch
by uncommentingnotmuch
withininit.el
beneath the:email
header. - Run
doom sync
in your shell. - Reload
doom emacs
by either killingemacs
and restarting, or by runningdoom/reload
(SPC : doom/reload
orSPC h r r
).
Configure notmuch
These steps are pulled from notmuch
’s own documentation (a).
Run
notmuch
in your shell to create~/.notmuch-config
.Perform initial indexing:
# Create a directory to house your mail if you don't already have one. mkdir -p /path/to/your/mail/directory cd /path/to/your/mail/directory notmuch new
You should see something like:
Found 0 total files (that's not much mail) No new mail.
Configure lieer
These steps are pulled from lieer
’s own documentation (a).
Make a directory for the lieer storage and state files (local repository).
cd /path/to/your/mail/directory mkdir <you>.gmail cd you.gmail
Update your
~/.notmuch-config
to ignorejson
,lock
, andbak
files by updating the[new]
section to read:[new] tags=new ignore=/.*[.](json|lock|bak)$/
Initialize your mail storage.
This command will open a new tab in your browser. We need to run this command once before we can specify our own credentials. Feel free to close the tab as soon as it opens as we’ll be swapping the default client id with our own in the next steps.
# From within /path/to/your/mail/directory/<you>.gmail /path/to/lieer/gmi init <you>@gmail.com
Cancel out (
CTRL-C
).You should see a message similar to:
init: repository is set up, but authorization failed. re-run 'gmi auth' with proper parameters to complete authorization
Set your credentials.
# From within /path/to/your/mail/directory/<you>.gmail /path/to/lieer/gmi auth \ --credentials=/path/to/your/OAuth2/client/id.json # Or, if you're working remotely (SSHing into your workstation, etc) /path/to/lieer/gmi \ --noauth_local_webserver \ auth \ --credentials=/path/to/your/OAuth2/client/id.json
Open the link and authenticate using your
@gmail.com
account. Copy the code and paste it back into the runninggmi
command. You should see a message like:Authentication successful. credentials stored in /path/to/your/mail/directory/you.gmail/.credentials.gmailieer.json
Sync your email.
This step may take a long time. My initial sync of 90k emails took 56 real-time minutes.
# From within /path/to/your/mail/directory/<you>.gmail /path/to/lieer/gmi sync
Sync emails periodically
You could also use a systemd
timer for this.
Create a new shell script to sync your email. Remember to
chmod 777
!#!/bin/bash cd /path/to/your/mail/directory/you.gmail /path/to/lieer/gmi sync
Configure the cronjob with
crontab -e
.# Sync email with lieer every three minutes. */3 * * * * bash /path/to/your/script/sync_email.sh
Configure notmuch
within emacs
(optional)
Set up saved searches (a).
Prevent wrapping text at 70 characters while composing an email:
;; This is valid in doom emacs. You may need to customize for other distributions. ;; Prevent wrapping at 70 characters in email composition. (add-hook! 'message-mode-hook 'turn-off-auto-fill) (add-hook! 'message-mode-hook 'visual-line-mode)
Done!
For those of you using doom emacs
(a), you can open notmuch from anywhere with SPC o m
.