Email-setup
Setting up E-mail
This tutorial is to show how to setup email receiving, indexing, sending and viewing it.
Understanding email in this context
For our purposes, an email is a file that is stored somewhere. A single email is a single file stored in a directory somewhere.
Requirements
- isync This program downloads mail from server. See man mbsync
- notmuch This program tags received mail and indexes them. For eg, an email about rock music can be tagged with "rock", "music", etc so that later, we can search them.
- afew This program is to handle automatic-tagging to notmuch. while it is possible to do it directly through notmuch, afew makes it easier
- emacs or neomutt or mutt This is the frontend where you read and write emails.
isync
mbsync is the program developed by isync project. mbsync looks for a file ~/.mbsyncrc for it's configuration. Since it downloads mail, it needs your password too. It's better to use app-passwords if your provider supports them and use `pass` to get password.
See it's arch-wiki page for more details. The structure and meaning of relevant block is included in the example
########################### # Conf for mbsync ######### # put this in ~/.mbsyncrc # ########################### #account name IMAPAccount NAME Host imap.domain.tld User name@domain.tld Pass "hunter2" #use pass with: #PassCmd sh script_name SSLType IMAPS CertificateFile /etc/ssl/certs/ca-certificates.crt #Store is a collection of mailboxes. Say you have mailboxes like #inbox, spam, trash, draft, etc, those are stored in a single store #Seperate accounts have seperate stores. IMAPStore NAME-remote Account NAME #here, local store is defined. you're going to download emails so #you'll have to tell it so save somewhere. MailDirStore NAME-local Subfolders Verbatim # / at end is important Path ~/mail/ Inbox ~/mail/Inbox channel NAME Far :NAME-remote: Near :NAME-local: #sync's all folders it can find. If you have a folder you don't want #to sync, use ! in the pattern. Like: "!Spam" Patterns * #if folder dosen't exists, make it. be it remote or local. Create Both #Saves synchronization state files. SyncState *
notmuch
Notmuch indexes mails so you can search within the mail. It also stores tags for organization. See `man notmuch` which has very good documentation.
Run `notmuch setup` so that it does all the initial heavylifting. Then, edit ~/.notmuch-config with the option below. The config file itself is very well written and you should read it.
After receiving mail, you should run `notmuch new`.
This config makes it so new mails are tagged with tag "new" only. Everything else should be handled by afew.
#Find the correct line and make it as below [new] tags=new; ignore=
afew
Afew makes it easy to automatically tag new messages into whatever tag you like. While notmuch can do it too, it is more complex and afew is a lot more easier to write filters.
You can even download filters from internet as python files that implement much complex filters. Just download filter and add it to ~/.config/afew/.
The man page of afew is very well written. Read it.
You can alias this command to run mbsync, notmuch and afew at once.
alias mailsync="mbsync -a && notmuch new && afew --tag --new"
emacs
Finally, to read messages, install `notmuch-emacs` package from your distro's repo. Then type `M-x notmuch` and view on a tag like `new` or `all mail`.