I manage my emails inside Emacs through the Mu4e email client. For syncing the mail folder, I use the mbsync
program from the isync
package and the mu
utility for the indexing.
If you wonder how you can expose Gmail categories - like Updates
or Promotions
- to IMAP, check this blog post. Labels are exposed by default, so don’t worry about them.
(use-package mu4e
:straight nil ;; mu4e is installed through the package manager
;:defer 20 ; Wait until 20 seconds after startup
:custom
(mu4e-compose-context-policy 'ask-if-none)
(mu4e-context-policy 'pick-first)
:config
;; use mu4e for e-mail in emacs
(setq mail-user-agent 'mu4e-user-agent)
;; This is set to 't' to avoid mail syncing issues when using mbsync
(setq mu4e-change-filenames-when-moving t)
;; Refresh mail interval in seconds
(setq mu4e-update-interval (* 2 60 60))
(setq mu4e-get-mail-command "mbsync -a")
(setq mu4e-maildir "~/Mail")
(setq mu4e-attachment-dir "~/Downloads")
(setq mu4e-contexts
(list
;; Main account
(make-mu4e-context
:name "Gmail"
:match-func
(lambda (msg)
(when msg
(string-prefix-p "/Gmail" (mu4e-message-field msg :maildir))))
:vars '((smtpmail-smtp-server . "smtp.gmail.com")
(smtpmail-smtp-service . 465)
(smtpmail-stream-type . ssl)
(user-mail-address . "luishenriquegh2701@gmail.com")
(user-full-name . "Luis Henrique Gomes Higino")
(mu4e-drafts-folder . "/Gmail/[Gmail]/Drafts")
(mu4e-sent-folder . "/Gmail/[Gmail]/Sent Mail")
(mu4e-refile-folder . "/Gmail/[Gmail]/All Mail")
(mu4e-trash-folder . "/Gmail/[Gmail]/Trash")
(mu4e-compose-signature . "Luis H. Higino")))
;; DCC/UFMG account
(make-mu4e-context
:name "DCC"
:match-func
(lambda (msg)
(when msg
(string-prefix-p "/DCC" (mu4e-message-field msg :maildir))))
:vars '((smtpmail-smtp-server . "smtp.dcc.ufmg.br")
(smtpmail-smtp-service . 587)
(smtpmail-stream-type . starttls)
(user-mail-address . "luis.higino@dcc.ufmg.br")
(user-full-name . "Luis Henrique Gomes Higino")
(mu4e-drafts-folder . "/DCC/Drafts")
(mu4e-sent-folder . "/DCC/Sent")
(mu4e-refile-folder . "/DCC/Archive")
(mu4e-trash-folder . "/DCC/Deleted Items")
(mu4e-compose-signature . "Luis H. Higino")))))
;; shortcuts
(setq mu4e-maildir-shortcuts
'((:maildir "/Gmail/primary" :key ?i)
(:maildir "/Gmail/updates-label" :key ?u)
(:maildir "/Gmail/promotions-label" :key ?p)
(:maildir "/Gmail/forums-label" :key ?f)
(:maildir "/Gmail/social-label" :key ?s)
(:maildir "/Gmail/[Gmail]/Sent Mail" :key ?S)
(:maildir "/Gmail/[Gmail]/Trash" :key ?T)
(:maildir "/Gmail/[Gmail]/Drafts" :key ?D)
(:maildir "/Gmail/[Gmail]/All Mail" :key ?A)))
;; setting mu4e to complete with completing-read
(setq mu4e-read-option-use-builtin nil
mu4e-completing-read-function 'completing-read)
;; Function to use for sending mail
(setq message-send-mail-function 'smtpmail-send-it)
;; Make sure plain text mails flow correctly for recipients
(setq mu4e-compose-format-flowed t)
;; Kill mail buffer when mail is sent
(setq message-kill-buffer-on-exit t)
;; Normal people's date format ;)
(setq mu4e-headers-date-format "%d/%m/%y")
;; :config
;; Requiring org helpers
(require 'mu4e-org)
;; custom actions
(defun lhgh/capture-mail-read-later (msg)
(interactive)
(call-interactively 'org-store-link)
(org-capture nil "mr"))
;; adding the custom actions to mu4e actions
(add-to-list 'mu4e-headers-actions
'("read later" . lhgh/capture-mail-read-later) t)
(add-to-list 'mu4e-view-actions
'("read later" . lhgh/capture-mail-read-later) t)
;; adding custom bookmarks
(add-to-list 'mu4e-bookmarks
'(:name "Academic messages" :query "m:/Gmail/academic or m:/DCC/Inbox" :key ?a))
;; Run mu4e in the background to sync mail periodically
(mu4e t))
IMAPAccount gmail
Host imap.gmail.com
SSLType IMAPS
AuthMechs LOGIN
User luishenriquegh2701@gmail.com
PassCmd "pass email/mbsync-gmail"
CertificateFile /etc/ssl/certs/ca-certificates.crt
IMAPStore gmail-remote
Account gmail
MaildirStore gmail-local
Subfolders Verbatim
Path ~/Mail/Gmail/
Inbox ~/Mail/Gmail/Inbox
Channel gmail
Far :gmail-remote:
Near :gmail-local:
Patterns * ![Gmail]* "[Gmail]/Sent Mail" "[Gmail]/Starred" "[Gmail]/All Mail" "[Gmail]/Trash"
Create Both
SyncState *
# DCC/UFMG account
IMAPAccount dcc
Host imap.dcc.ufmg.br
SSLType IMAPS
AuthMechs LOGIN
User luis.higino
PassCmd "pass academic/dcc.ufmg.br"
CertificateFile /etc/ssl/certs/ca-certificates.crt
IMAPStore dcc-remote
Account dcc
MaildirStore dcc-local
Subfolders Verbatim
Path ~/Mail/DCC/
Inbox ~/Mail/DCC/Inbox
Trash "~/Mail/DCC/Deleted Items"
Channel dcc
Far :dcc-remote:
Near :dcc-local:
Patterns *
Expunge None
CopyArrivalDate yes
Sync All
Create Both
SyncState *
(provide 'lhgh-mail)
(specifications->manifest
'("mu"
"isync"))