This is what I ended up doing, and have been using it this way since December.
It's a lot of work to setup though, as you need to install and configure postfix (for SMTP) and dovecot (POP/IMAP) at the bare minimum. I also added a bunch of other features for anti-spam such as spam-assassin, postgrey (grey-listing rejects e-mail from unknown sources, forcing them to resend after a delay if they're legitimate), and sieve (which performs the actual filtering of spam into a junk folder).
If you want web-mail then you also need to setup a web server and usually PHP (I did nginx, MariaDB and PHP7), plus the web-mail service itself (I opted for Roundcube with the manage sieve plugin).
You also need some form of backup strategy; I ended up writing a script to perform local incremental rsync back-ups, plus another script to send those back-ups to Dream Objects via Duplicity.
Oh, and you also want to setup security certificates so you can use SSL connections; I opted to use Let's Encrypt as a provider for this as you can write another script to automatically install and refresh your certificates, in this case you definitely need the web-server components as you need to be able to verify the domain(s) are yours.
It took me the better part of two weeks to get everything set up and configured, plus I've had to make a few tweaks or here or there, and have to periodically install updates.
I actually kind of enjoyed setting everything up and tweaking it all to the best of my ability. The main challenge is finding good guides to follow as so much stuff is out of date if you look for tutorials, but the official guides for each product aren't always the best. Having total control does have its advantages though, as you can enable a bunch of features that Dreamhost don't (for simplicity), plus the end result can be incredibly lean (I got everything running on a basic Dream Compute instance with almost half its memory to spare, though I'm going to either upgrade to the more powerful instance or get a second one at some point).
The guide I mostly followed was from Arstechnica and can be found here (it's in four parts). It's not completely up-to-date, so anywhere it mentions downloading a package with git you'll want to have a look in aptitude first as it's probably already there; except for Roundcube I don't recall having to download any packages outside of aptitude. They also use Startssl for encryption but I'd recommend Let's Encrypt; if you only have the one domain to encrypt then it's pretty easy to configure, in fact if you setup nginx then the command to update it is dead easy, you just need to make sure you also reload dovecot and postfix afterwards (so they use the updated certificate too).
Hope this helps; if it puts you off then it probably should, as it's not an easy thing to do. If you're pretty confident with command line Linux though it might be worth a try; the free trial period is long enough that you could try setting it up then actually move stuff across later, for transitioning I held onto my Dreamhost e-mail account by using mail.dreamhost.com to connect to it, this way even once you redirect the domain to your new e-mail server you can still grab your current mail and transfer it across. I found this preferable to restoring from a local copy as apparently what OS X Mail calls "mbox" format isn't what everybody else considers it to be. Dragging and dropping in a mail client is slow, but it actually works.