How to Host Your Own Email Server

luispa2 pts0 comments

How to Host your Own Email Server - miguelgrinberg.com

How to Host your Own Email Server

Posted by

on<br>2026-03-06T16:10:41Z<br>under

I recently started a new platform where I sell my books and courses, and in this website I needed to send account related emails to my users for things such as email address verification and password reset requests. The reasonable option that is often suggested is to use a paid email service such as Mailgun or SendGrid. Sending emails on your own is, according to the Internet, too difficult.

Because the prospect of adding yet another dependency on Big Tech is depressing, I decided to go against the general advice and roll my own email server. And sure, it wasn't trivial, but it wasn't all that hard either!

Are you interested in hosting your own email server, like me? In this article I'll tell you how to go from nothing to being able to send emails that are accepted by all the big email players. My main concern is sending, but I will also cover the simple solution that I'm using to receive emails and replies.

This is a longer read than my usual blog posts, and some of the steps involve waiting, so unfortunately you will not be able to set up your email server all in one day. To help you find your place as you follow these instructions over several sessions, I'm including a table of contents that will help you jump directly to each step.

High-level design

Requirements

Preparation

Basic DNS setup

Email forwarding

Postfix

Send a test email

Reverse DNS

DKIM

SPF

DMARC

Have patience

High-level design

Knowing in advance that I was going to attempt something that most people consider to be very hard, I wanted to design the simplest possible solution that allowed my web application to send emails out to people. I did not want to have to worry about other email use cases. At least not initially.

So what is there to simplify when thinking about email? I started from the two major protocols related to email:

SMTP , the Simple Mail Transfer Protocol: This is the protocol that allows email servers to talk between each other to send and receive messages. The two popular open source SMTP servers are Sendmail and Postfix.

IMAP , the Internet Message Access Protocol: A protocol that lets a user access and manage email stored in a remote server. A lot of people use Dovecot for IMAP.

Really the only thing you need to send emails is SMTP. IMAP is for accessing emails, not sending them. So from the start I decided to skip IMAP.

But I was able to simplify things even more. The "receiving" side of SMTP was also a bit annoying to have to support, as that involves managing user accounts and mailboxes in my server, and more importantly, it would require me to monitor one or more new email addresses for incoming mail. For many years I have relied on the email forwarding feature included with my domain to have those occasional emails people send to me at a @miguelgrinberg.com address redirected to my personal email address, and this works really well for me.

So the simplest email solution I could come up with involved an asymmetric SMTP configuration. I would use my self-hosted SMTP server for sending emails, but for receiving I would continue to use the email forwarding service that I'm currently using. This meant that I could host my email server securely behind a firewall, because it would not need to be in the receive path, and consequently it would not need to accept connections from other servers.

Requirements

Running an email server requires basically two things, and you probably have both already. You need a domain name, and a computer to run the server on. That's pretty much it in terms of things that cost money.

Having a domain is actually required to send emails on your own. You will see later that a lot of the configuration work involves changing settings on the domain and not directly on the server. If you have a domain for your website or business, then you're good to go.

As far as the computer that will run your server, you will need to have it on 24/7.

Using a Raspberry Pi or old PC in your home seems like a decent idea, but I do not recommend it. The main problem with running your email server at home is that most ISPs do not assign you a fixed IP address, and this creates a lot of complications for email servers, since it is difficult to keep your domain DNS entries up to date when your IP address can change at any time. Also, any sender reputation you accumulate when the server is on one IP address could go away when your IP address changes and other servers do not recognize you anymore. I only recommend running your server at home if your ISP gives you a fixed IP address.

The best option to host your email server is to get a cheap Virtual Private Server (VPS) from Hetzner, Digital Ocean, Linode, or similar providers, which all come with a fixed IPv4 address. If you already have a VPS for your website, you may be able to squeeze the SMTP server in it...

email server emails address send smtp

Related Articles