[Emacs] mu4e + offlineimap multiply accounts

I'm using Emacs every day, almost for all, in fact i need only two user-level applications at my computer, they are Emacs and web browser (despite on eww in Emacs 25). I use Emacs almost for all, for text editing, for chatting in irc, email reading/writing, files manipulations, as my TODO list and many many more (and this blog post was written in Emacs too). Today i want to tell how to use Emacs for email handling. I will show how to install mu4e and offlineimap and configure Eemacs for handling emails from multiply accounts with this tools in ubuntu-14.10. If you're interesting read next.

Installing


Emacs

Of course first of all you must have installed Emacs on your computer. You can download it from here and build it from source. Or you just can use apt-get package manager and install Emacs with:
sudo apt-get install Emacs
mu4e

mu4e it is a emacs-based e-mail client. You can install it with following commands:
sudo apt-get install html2text xdg-utils libgmime-2.6-dev libxapian-dev
git clone https://github.com/djcb/mu
cd mu && autoreconf -i && ./configure && make
sudo make install
After these commands execution mu and mu4e should be installed.

offlineimap

OfflineIMAP is a Python utility to sync mail from IMAP servers. We can install it with:
sudo apt-get install offlineimap

offlineimap configuration


After we have installed all software, we can start to configurate it. Let's start from offlineimap configuration. As i wrote about this post will be about multiply accounts configuration, I personally have two email accounts for work and personal. Let's call it Work and Personal. For offlineimap configuration open/create ~/.offlineimaprc file. Offlineimap configuration file consists from sections and key value records separated with = symbol. Let's add first section to ~/.offlieimaprc:



First sectrion is general. It contains two values: first is 'accounts', we declare names for our accounts. Second is 'maxsyncaccounts', it controls how many accounts may be synced simultaneously. Next we'll define sections for first 'Work' account:


There are 3 sections for remote and local repository. First [Account Work] defines local and remote repository. Second section defines type of mail directory, it is a Maildir and path to it. Third section defines remote host parameters as user email, user host, protocol type (IMAP), ssl and etc... Of course you will need to change some parameters to your own values. After this we must define the same 3 sections for Personal account, it will contain the same fields as first, like this:


Here we can see the same sections and fields as for first account, little difference that it configured for gmail IMAP server. After this go to you terminal and execute:
mkdir -p ~/Maildir/Work
mkdir -p ~/Maildir/Personal
cd /home/user
offlineimap
It will fetches all mail from your mail servers, so you can work with it in Emacs.

Emacs configuration


As we have installed Emacs, mu4e and also we have configured offlineimap, we can go to Emacs configuration. First of all you need to tell Emacs where to load mu4e and enable it and smtpmail package with:


Now we define some general variables for both accounts with:


As i said here we define general parameters for our both accounts, they are program for fetching email (offlineimap in our case), updating interval, what we'll use for email sending (smtpmail in our case), maildir shortcuts (we'll describe it later), directory for attachment, and email message signature auto-inserting. Now we must add yet variables to define fields which are different for our 2 accounts:


They are following fields: settings for you smtp servers, signatures and user info. And add one function for choosing account before message composing:


Technically that's all, but you can add some more customization like date formating, image displaying and etc...:


Usage


Ok, we configured emacs, mu4e and offlineimap. Time to use it. First of all i have added keybinding for openning mu4e:


Of course you can choose another key combination. Now after pressing F1, i see mu4e main window:
It is mu4e main view in Emacs. You can do following actions here:
  • U - update email for both accounts
  • q - exit from mu4e
  • j-k - go to personal inbox (remember we defined keybindings in mu4e-maildir-shortcuts
  • j-w - go to work inbox
  • C - compose new message, it will ask you from what account you want to send message

Conclusion


This is the end. In this post i told how to configure Emacs + mu4e + offlineimap for email handling. As a longtime Emacs user I'm very interesting how and for what do you using Emacs, what extensions and what tasks Emacs helps to solve you, write me a comment about it. Hope this post was useful for you.

p.s. English is not my first language, so you'll find mistakes in blog post please write me in comments, ping me at twitter - twitter, or drop me email.

Comments