The Ultimate Emailing Agent with Mu4e and Emacs

Posted by:

1 Mu4e in Arch Linux


2 Install mu and config mu4e for Emacs

mu4e will be installed with mu, or grab it from github. mu4e-multi is the simpliest way to set up mu4e setting.

3 Use getmail to retrieve your email from all your account

3.1 The email directoy system

I prefer maildir directory system here – a directory that stores email messages as files. The folders inside the mail directory are subdirectories such as .Drafts .Trash and .Sent. Each of these folders contain three additional subdirectories called tmp, new and cur. tmp – This subdirectory stores email messages that are in the process of being delivered. It may also store other kinds of temporary files. new – This subdirectory stores messages that have been delivered but have not yet been seen by any mail application, such as webmail or Outlook. cur – This subdirectory stores messages that have already been viewed by mail applications, like webmail or Outlook.

3.2 Install and configure getmail to retrieve emails

NOTE: use getmail from this link if you want passworddeval capability. getmail ( with “passwordeval” receiver option so that the password can be received from an external program instead of being stored clear text in the config file. use separate rc file for each account (two gmails and one exchange server) set destination =MDA-external and path to procmail rc file for each account to further process emails. create maildir directories within each account.

Following is getmail rc file for one account.

3.3 Automate the process –using a script file.

emailing setting

4 Install davmail for exchange server access

use the correct exchange server url (davmail needed with owa: in my case). check with your IT if needed. use locallost and davmail port# in getmail

5 Process emails with Procmail

Each procmail rc corresponds to each account Note:

  1. Comment out path to prevent mu -index to
  2. good instruction here for Spamassassin, and isbg for IMAP folder filtering.
  3. You may need to install docopt if you do not have it in your system.

6 Filter and protection with Spamassassin and Clamvirus

6.1 Spamassassin installation and setting

  1. Download and install from apache official site, compile and install
  2. or install from arch repos

    check with sample test mail to make sure it running.

  3. Add following recipes in procmail rc file

  4. That should be it. You can play with the config files such as adding blacklist and whitelist etc follow this link.

6.2 ClamAV installation and setting -base one official Arch site.

  1. Install from arch repos

  2. Confirm it is working

    The output must include:

  3. copy following into procmail rc settings

6.3 Add more personal flavor to your recipe

I just modify following based on each of accounts, like it so far.

7 MSMTP for sending emails, follow instruction here.

  1. configure each account info with credentials.

  2. Dot-emacs setting for signature for each account After all the fiddling, it turn out to be this is the easiest way for me. link here

8 Use GnuPG to encrypt password in a file instead of clear password

  1. Install GnuPG and PGP-agent. It is pretty straight-forward with GnuPG installation, just follow Arch Official Site and informative tutorial, or Gentoo Info. Note: By default $GNUPGHOME isn’t set and your $HOME is used instead, thus you will find a ~/.gnupg directory right after the install.
  2. gpg-agent is mostly used as daemon to request and cache the password whenever it needs the password. This is useful if GnuPG is used from an external program like a mail client. It can be activated by adding following line in gpg.conf:

  3. Add the following entry to your .xinitrc or .bash_profile to autostart it.

  4. Logout and log back in, check if pgp-agent activated:

  5. The gpg-agent can be configured via ~/.gnupg/gpg-agent.conf file, such information as cache interval and how to ask user to input password (pinentry is used here since it installed along with GnupG in Arch Linux).

    Note: an empty gpg-agent.env was also created to remove the complain at initial login.

  6. Reload the agent

    The shell should print OK.

  7. Install getmail with “passwordeval” branch, download from here, unload the default getmail FIRST Navigate to download folder and unzip; Do the following as a regular user:

    Then (probably as root), do:

  8. Generate password file for each of your email account, adapted from here.

    “passowrd” is your email account password, use single quote if you have special character in your password (e.g. ! @ etc). Input your email used for GnuPG key generation, and RET again to finish.

  9. Confirm your password with following:

  10. Add following to your .msmtprc (for sending emails) and .getmailrc files (for retrieving emails):

    delete your password line.

  11. Confirm you that you can still retrieve emails with getmail.

  12. That is it!!

9 Sending email notification with cron link

  1. install msmtp-mta which creates a symbolic link from /usr/bin/sendmail to /usr/bin/msmtp
  2. create /etc/msmtprc and append

  3. and create /etc/aliases:

  4. Then modify the configuration of cronie daemon by replacing the with email notification link ExecStart command with:

  5. verified working, and yes, it is working fine, kind of annoying though with email notification.
  6. Disable it

    disable the cron job by “#” to comment out the line

  7. set up mu4e in dot-emacs file to check and index emails at desirable interval

10 Creating org-mode links to emails for reminder and GTD purpose

  1. activate in dot-emacs configuration file

  2. in Headers View or Message View, C-c l
  3. initialize org-mode file, C-c C-l, TAB to choose stored links
  4. C-c C-o or RET to open at point
  5. C-c C-l with cursor on existing link, to edit link
  6. Official site for more

11 The keybindings and cheatsheet from mu4e official site.

11.1 The cheatsheet for mu is here.

11.2 The list of useful queries

refer to mu-find and mu-easy man pages.

Function Notes
from:john flag:attach panda messages with attach about panda from john
from:jim AND NOT flag: attach all messages from jim without attach
Contact: alice messages with alice in contact fields (to, from and cc)
date: subject:mu4e last 2 weeks emails about mu4e subject
file: pic* all emails with attachments with filenames starting with pic
mime:Application/pdf emails with pdf attachments
mime:image/* emails with image attachments

NB: press s to start search in header view.

11.3 Navigate The Views of Mu4e:

11.4 The keybindings

11.4.1 key description

n,p view the next, previous message
],[ move to the next, previous unread message
y select the message view (if it’s visible)
RET open the message at point in the message view

11.4.2 searching

s search
S edit last query
| narrow the search
b search bookmark
B edit bookmark before search
j jump to maildir
M-left,\ previous query
M-right next query
O change sort order
P toggle threading
Q toggle full-search
V toggle skip-duplicates
W toggle include-related

11.4.3 marking

d mark for moving to the trash folder
= mark for removing trash flag (‘untrash’)
DEL,D mark for complete deletion
m mark for moving to another maildir folder
r mark for refiling
+,- mark for flagging/unflagging
?,! mark message as unread, read
u unmark message at point
U unmark all messages
% mark based on a regular expression
T,t mark whole thread, subthread
<insert>,* mark for ‘something’ (decide later)
# resolve deferred ‘something’ marks
x execute actions for the marked messages

11.4.4 composition

R,F,C reply/forward/compose
E edit (only allowed for draft messages)

11.4.5 misc

a execute some custom action on a header
\ pipe message through shell command
C-+,C– increase / decrease the number of headers shown
H get help
C-S-u update mail & reindex
q,z leave the headers buffer

11.4.6 Useful keybindings mu4e’s editor view

C-c C-c send message
C-c C-d save to drafts and leave
C-c C-k kill the message
C-c C-a ` attach a file (pro-tip: drag & drop works as well)
C-S-u update mail & reindex


  1. Timothy Fry  October 23, 2016

    Thanks for putting this together! I find myself very tired of most Linux mail clients and am allured by the simplicity and “usability” of having my mail right in Emacs.

    Your overview is far more complete and valuable than anything else I’ve found. Just seeing how you wrote the rc files answered many questions I had with greater clarity than the documentation or the Arch Wiki was able to provide.

    I appreciate your time and effort. (-:


Leave a Reply to mistan
click here to cancel reply