< B / >

Setting Up Email in Doom Emacs with mu4e on NixOS with Home Manager

On some days I feel like I’ve dug my own grave.

My day started out in a pretty innocent way. I’m currently reading The Great CEO Within, and came across a section on Getting Things Done especially tailored towards Email.
Since having an Email Client + workflow I can halfway be productive with has been something I’ve had on top of my chore list, I gave it another try—and immediately remembered why I’ve stopped the last few times:

  • Email itself is tech-wise insanely complex and hard to work with
  • It comes from a very different world. In this world, it has inherent and fatal flaws
  • Every non-technical Email tool has some magic baked in that makes it magically go away (and you not aware of it—that’s the problem)

That taken together makes it a pretty daunting task.

But this time, it didn’t stop me.

§ Understanding Email

To work with Email, you need three things:

  1. A program to sync your email from a server to a local folder
  2. A program to read/view/search your email from that folder
  3. A program to reply to emails from that folder/send new emails

The programs we’re going to use in this guide are mbsync (1.), mu (2.) and msmtp(3.).

First, we’re gonna get your system to a state you can start from, then get it to work on the command line, and only then set it up in Doom Emacs.

§ 1. Getting the system to a state you can start from

From here on, this post assumes that you’ve got:

  1. Nix installed
  2. Home Manager installed

(Since you came here you probably know it, but) The Home Manager Email Options are weird, at least at first.

The way they work is that you define an email account:

accounts.email.accounts = {
posteo = {
address = "[email protected]";
realName = "Beat Hagenlocher";
userName = "[email protected]";
passwordCommand = "cat ~/.posteopassword";
};
};

How to access the server for sending and pulling Email:

accounts.email.accounts = {
posteo = {
# ...
smtp = {
host = "posteo.de";
port = 465;
tls.enable = true;
};
imap = {
host = "posteo.de";
port = 993;
tls.enable = true;
};
};
};

As well as the configuration options per account for the tools you might use (mbsync, mu, and msmtp for us):

accounts.email.accounts = {
posteo = {
# ...
mbsync = {
enable = true;
create = "both";
remove = "both";
expunge = "both";
};
mu.enable = true;
msmtp.enable = true;
};
};

Taken together:

accounts.email.accounts = {
posteo = {
address = "[email protected]";
realName = "Beat Hagenlocher";
userName = "[email protected]";
passwordCommand = "cat ~/.posteopassword";
smtp = {
host = "posteo.de";
port = 465;
tls.enable = true;
};
imap = {
host = "posteo.de";
port = 993;
tls.enable = true;
};
mbsync = {
enable = true;
create = "both";
remove = "both";
expunge = "both";
};
mu.enable = true;
msmtp.enable = true;
};
};

Now, we only need to enable mbsync, mu and msmtp:

programs.mbsync.enable = true;
programs.msmtp.enable = true;
programs.mu.enable = true;
accounts.email.accounts = {
# ...
};
programs.mbsync.enable = true;
programs.msmtp.enable = true;
programs.mu.enable = true;
accounts.email.accounts = {
posteo = {
primary = true;
address = "[email protected]";
realName = "Beat Hagenlocher";
userName = "[email protected]";
passwordCommand = "cat ~/.posteopassword";
signature = {
text = ''
Liebe Grüße
Beat Hagenlocher
'';
showSignature = "append";
};
smtp = {
host = "posteo.de";
port = 465;
tls.enable = true;
};
imap = {
host = "posteo.de";
port = 993;
tls.enable = true;
};
mbsync = {
enable = true;
create = "both";
remove = "both";
expunge = "both";
patterns = [
"*"
"!Drafts"
"!Deleted Messages"
];
};
msmtp = {
enable = true;
};
};
};

This is what my full config looks like: https://github.com/haglobah/nix-home/blob/main/home.nix#L187