8

reading gmail mails with emacs

 2 years ago
source link: https://allsyed.com/posts/manage-gmail-with-emacs-part-1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
📅 Dec 23, 2020  ·  ☕ 3 min read  ·  ✍️ Syed Dawood
Featured Image

Intro

mu is a tool for dealing with e-mail messages stored in the Maildir-format, on Unix-like systems. mu’s main purpose is to help you to find the messages you need, quickly; in addition, it allows you to view messages, extract attachments

mu

Prerequisites

  • Emacs
  • emacs-lisp
  • Being comfortable with command line
  • Curiosity to try

G-Mail gives a nice intuitive UI for interacting with mail. There are lots of disadvantages with it.

  • Connection to internet
  • Bloated, there are too many options.
  • Heavy, Every page load on an average transfers ~25MB
  • Limited search capabilities,

Login Page

Gmail settings

Enable IMAP

⚙️ > See all settings > Forwarding and POP/Imap

In IMAP section, Enable IMAP if not enabled.Set Auto Expunge off , Move to trash and save changes. Next up is password, There are 2 ways to go about it depending on 2-Factor authentication status. If 2-Factor is not enabled, then Less Secure App must be enabled. For accounts with 2-Factor enabled, create an App password if you don’t have one.

IMAP settings

Installation and Setup

Install

Instructions here will vary from distro to distro.

sudo apt install isync

Set Up

Create a file in home directory .mbsyncrc with content below. replace <EMAIL> with your email and <PASSWORD> with your password accordingly.

Having password in plain text is a bad idea if you are on a public machine, even on personal computer. You can use gpg to encrypt password or use password store provided by your distribution.

IMAPAccount account-1
Host imap.gmail.com
User <EMAIL>
Pass "<PASSWORD>"
#AuthMechs LOGIN
SSLType IMAPS
CertificateFile /etc/ssl/certs/ca-certificates.crt

IMAPStore account-1-remote
Account account-1

MaildirStore account-1-local
Subfolders Verbatim
Path ~/.local/share/mail/<EMAIL>/
Inbox ~/.local/share/mail/<EMAIL>/INBOX
#Flatten .

Channel account-1
#Expunge Both
Master :account-1-remote:
Slave :account-1-local:
Patterns * ![Gmail]* "[Gmail]/Sent Mail" "[Gmail]/Starred" "[Gmail]/All Mail"
Create Both
SyncState *
MaxMessages 0
ExpireUnread no

mbsync will throw an error if path is not created. Create directories with the command below

mkdir -p $HOME/.local/share/mail/<EMAIL>/

Next up syncing mails. For testing purposes, first time do this from terminal. It may take some time to complete if you have lots of mails.

mbsync -a

mbsync
Now, We have all the mails in on machine in a local folder. We have to tell mu to index our mails.

For mu older than v1.3.8

mu index --maildir=~/.local/share/mail/<EMAIL>/ --my-address=<EMAIL>

Newer mu version,

mu init --maildir=~/.local/share/mail/<EMAIL>/ --my-address=<EMAIL>;
mu index

mbsync

Final step, Configure mu4e to read emails. Add the below confurations to init.el

(use-package mu4e
  :ensure nil
  :config
  (setq mu4e-change-filenames-when-moving t
        mu4e-update-interval 900 ;; seconds
        mu4e-get-mail-command "mbsync -a"
        mu4e-maildir "~/.local/share/mail"
        mu4e-drafts-folder "/[Gmail]/Drafts"
        mu4e-sent-folder   "/[Gmail]/Sent Mail"
        mu4e-refile-folder "/[Gmail]/All Mail"
        mu4e-trash-folder  "/[Gmail]/Trash")
  (mu4e t)

save file and restart emacs. To launch mu4e, meta(Alt) + x aka M-x , type mu4e and enter.

Conclusion & Further reading

For someone like me, who lives in terminal. mu4e is perfect, I recommend reading through manual . I have in the past used neomutt , it is a full-blown email client, Only issue with neomutt is new mails notifications, despite trying several solutions. I couldn’t get it work. mu4e have a package for showing desktop Notifications .

References


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK