The Ultimate Emailing Agent with Mu4e and Emacs

Posted by:

1 Mu4e in Arch Linux

scn_mu4e.png

2 Installation

l mu and config mu4e for Emacs mu4e will be installed with mu, or grab it from github.


Move the mu4e folder to your load-path (in my case, “~/.emacs.d/dotEmacs/”), OR, soft-link it.


Then configure .emacs as the following.


mu4e-multi and mu4e-maildirs-extension are the simplest 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. or install from AUR (en) – getmail-passwordeval AUR for Arch Linux. getmail (http://pyropus.ca/software/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 http://pyropus.ca/software/getmail/getmailrc-examples


4 Install davmail for exchange server access

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

davmailSettings.png

If encounter following issue, modify getmail script:

Solving getmail protocol error when used with DavMail | My Experience 101

It worked but the e-mails was being duplicated everytime I pull it with getmail despite the fact that I have “read_all = false” in my configuration file to only pull new messages. After painful debugging I saw the below error, which occur when after pulling the last e-mail and seems it ignore saving the state so next time it pull everything from the begining getmailrc: protocol error (command: CLOSE => socket error: EOF)

Debugging further, I found in the file getmail, which is a python script, around line 342 that when this protocol error occurs the retriever abort and does not save the stat. So simply replacing it with retriever.quit() solved the problem! except (poplib.error_proto, imaplib.IMAP4.abort), o: errorexit = True #retriever.abort() retriever.quit() # My Hack to solve duplicate messages

UPDATE: for office 365:

Office 365 Office 365 EWS endpoint is now standard for all customers: https://outlook.office365.com/EWS/Exchange.asmx Also make sure you set mode to EWS in settings

-— from here

5 Process emails with Procmail

Each procmail rc corresponds to each account Note:

  1. Comment out path to prevent mu -index to /root/.mu/xipian
  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 Other Features

  1. Email attachment reminders in mu4e see code here.
  2. Email alias for group emailing here

12 The keybindings and cheatsheet from mu4e official site.

12.1 The cheatsheet for mu is here.

12.2 The list of useful queries

refer to man mu-find, man mu-easy and man mu-query man pages and here.

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: 2w..now 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
mime:application/msword emails with attachments in Word Format (.doc)
mime:application/vnd.openxmlformats-officedocument.wordprocessingml.document (.docx)
maildir:/MIS emails under maildir Note: slash
flag:attach emails with attachments

Note:

  1. press s to start search in header view.
  2. man mu-query or mu-easy for more examples.
  3. The query is case-insensitive.
  4. to or from use email address instead of name; it works with names without quote.
  5. refer to here for a list of Incomplete list of MIME types – HTTP | MDN.
  6. BUGS? subject:“Google Alerts” does not work, it works without “”; WORKS with the new version now
  7. sth like PR-132 need to use regex //
  8. Other formats:

    Extension Kind of document MIME Type
    .xls Microsoft Excel application/vnd.ms-excel
    .xlsx Microsoft Excel (OpenXML) application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    .tar Tape Archive (TAR) application/x-tar
    .tiff .tif Tagged Image File Format (TIFF) image/tiff
    .ppt Microsoft PowerPoint application/vnd.ms-powerpoint
    .pptx Microsoft PowerPoint (OpenXML) application/vnd.openxmlformats-officedocument.presentationml.presentation
    .jpg .jpeg JPEG images image/jpeg
    .mpeg MPEG Video video/mpeg
    .wav Waveform Audio Format audio/wav

12.3 Navigate The Views of Mu4e:


12.4 The keybindings

12.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

12.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
   

12.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

12.4.4 composition

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

12.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

12.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)
(mu4e-specific)  
C-S-u update mail & reindex

dsdssd sd

3

Comments

  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. (-:

    reply
  2. zac  October 22, 2017

    I do think it’s a great post, especially the navigate table, easy to be understood. thanks for your time.

    reply

Leave a Reply to mistan
click here to cancel reply