How to set up mail in emacs with mu4e
Table of Contents
I was considering for a while to use mail in emacs, I didn't have the time to work on that, and I didn't find a tutorial up to date to just copy and paste, there are some good sources and documentation, but the implementation was not that straightforward, it took me a couple of days to find why It didn't work out my implementations.
Figure 1: mail
But here is the step by step. I have been using Migadu for a while, and It works quite well
1. Software Installation
- It will require to install:
- mu4e
- isync/mbsync
- msmtp
sudo apt install isync
Create a new file ~/.mbsyncrc
IMAPAccount migadu
Host imap.migadu.com
User mail@mymail.xyz
PassCmd "pass mail/my_mail_password"
TLSType IMAPS
CertificateFile /etc/ssl/certs/ca-certificates.crt
#AuthMechs Login
Port 993
IMAPStore migadu-remote
Account migadu
MaildirStore migadu-local
Path ~/Mail/migadu/
Inbox ~/Mail/migadu/INBOX/
Trash ~/Mail/migadu/Trash/
SubFolders Verbatim
Channel migadu
Far :migadu-remote:
Near :migadu-local:
Patterns *
CopyArrivalDate yes
Create Both
Sync All
SyncState *
Then, make sure to run in the terminal the following statement:
mu init --maildir=DIR --my-address=ADDRESS
then run:
mu index
2. Set up Emacs
Go to your init.el and write this snippet
(use-package mu4e
:ensure nil
;; :load-path "/usr/share/emacs/site-lisp/mu4e/"
:defer 20 ; Wait until 20 seconds after startup
:config
;; This is set to 't' to avoid mail syncing issues when using mbsync
(setq mu4e-change-filenames-when-moving t)
(setq mail-user-agent 'mu4e-user-agent)
;; Refresh mail using isync every 10 minutes
;;(setq mu4e-update-interval (* 10 60))
;;(setq mu4e-get-mail-command "mbsync -a")
(setq mu4e-get-mail-command (concat (executable-find "mbsync") " -a"))
;; how often to call it in seconds:
(setq mu4e-update-interval 300)
(setq mu4e-maildir "~/Mail/migadu")
(setq mu4e-drafts-folder "/Drafts")
(setq mu4e-sent-folder "/Sent")
(setq mu4e-refile-folder "/All")
(setq mu4e-trash-folder "/Trash")
(setq mu4e-junk-folder "/Junk")
(setq mu4e-others-folder "/Others")
(setq mu4e-maildir-shortcuts
'(("/INBOX" . ?i)
("/Sent" . ?s)
("/Trash" . ?t)
("/Drafts" . ?d)
("/Junk" . ?a)
("/Others" . ?o)
))
(mu4e t))
With this you can run mu4e inside emacs and you should see how your system is pulling up your emails. But notice is not ready to send emails yet, we need to consider an extra customization.
3. Sending emails with msmtp
Make sure to install msmtp (sudo apt install ) and create a file ~/.msmtprc, and write the following
defaults auth on tls on port 587 tls_trust_file /etc/ssl/certs/ca-certificates.crt logfile ~/.msmtp.log account personal host smtp.migadu.com from mail@mymail.xyz user mail@mymail.xyz passwordeval pass mail/mail@my_mail_password | head -1 account default : personal
Finally write in your emacs 'init.el' this.
(setq
message-send-mail-function 'smtpmail-send-it
smtpmail-default-smtp-server "smtp.migadu.com"
smtpmail-smtp-server "smtp.migadu.com"
smtpmail-local-domain "migadu.com"
)
(setq sendmail-program "/usr/bin/msmtp")
(setq message-sendmail-extra-arguments '("--read-envelope-from"))
(setq message-sendmail-f-is-evil t)
(setq message-send-mail-function 'message-send-mail-with-sendmail)
Then you should ready to go, enjoy the spam…