Skip to content

Instantly share code, notes, and snippets.

@F1LT3R
Last active June 20, 2023 03:27
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save F1LT3R/7ab6296bc687e6f18f13 to your computer and use it in GitHub Desktop.
Save F1LT3R/7ab6296bc687e6f18f13 to your computer and use it in GitHub Desktop.
Self-Hosted Email Server

#Self-Hosted Email Server

This guide shows you how to set up a self-hosted email server.

##The Stack

Stack Diagram

###At The Core

  • VirtualBox - hosts Vagrant
  • Vagrant - hosts Ubuntu
  • Ubuntu - hosts *all the things*

###The Email Software

  • Node.js - Runs Haraka
  • Haraka - SMTP Server (runs on Node.js)
  • Dovecot - Mail Delivery Agent (as IMAP server)
  • Roundcube - WebMail Client
  • MySQL - Roundcube state
  • PHP - Process HTTP/MySQL content for Roundcube
  • Nginx - Serves Roundcube views processed by PHP

##Setup

###Installing Ubuntu & Vagrant

[download and install virtualbox: https://www.virtualbox.org/wiki/Downloads] [download and install vagrant: https://www.vagrantup.com/downloads]

// Initialize Vagrant with latest Ubuntu
vagrant init ubuntu/trusty64

// Start Vagrant
vagrant up

// Downloading and installing of Ubuntu happens now...

###Make Vagrant available locally

Next we need to edit the vagrant file to resolve to a local ip, so we can access HTML content over the local network when hitting the nginx server running on vagrant.

// Edit vagrantfile settings (lets do some networking stuff)
edit vagrantfile

// Allow the Vagrant box to be seen locally
config.vm.network "private_network", ip: "10.0.0.2"

// Restart Vagrant
vagrant reload

// This time it is quick because we already installed Ubuntu

###Installing Nginx Web Server

// Restart the Vagrant VM now IP setting is changed
vagrant reload

// log into vagrant vm
vagrant ssh

// update the package manager
sudo apt-get update

// update the package manager
sudo apt-get install nginx

// Start Nginx
sudo service nginx restart

Go to local browser and try http://10.0.0.2 in to the address bar and you should see a web page sating: "Welcome to nginx!".

Screenshot of Nginx Page

###Installing Haraka SMTP Server

Haraka is the STMP server. SMTP stands for Simple Mail Transfer Protocol. Think of the SMTP server as the relay system for a post office: including the postmen, the post vans, the works delivering and collecting the mail, the warehouse the routes the mail and passes on to the next address.

Haraka is extremely fast, scalable and extensible. It is currently being used by Criagslist.org for their complex SMTP needs. Haraka sits on top of Node.js, so lets get that installed...

// Install node.js
sudo apt-get install nodejs

// Install NPM (Node Package Manager)
sudo apt-get install npm

// Install Haraka
sudo npm install Haraka -g

Detailed instructions for setting up Haraka can be found here: https://www.youtube.com/watch?v=6twKXMAsPsw

###Install Dovecot

Dovecot is an MDA. MDA stands for Mail Delivery Agent. Think of this as the letter box in front of your house. It is the place the mail is delivered, and collected by the SMTP server. There are different ways to store the mail, maildir, IMAP, etc. IMAP is a nice way to store mail, so lets use Dovecot to handle that task.

// Install Dovecot
sudo apt-get install dovecot-imapd dovecot-pop3d

// Choose [No] for SSL Certificate

dovecot -n
cd /var/mail/
sudo nano /etc/dovecot/dovecot.conf
    disable_plaintext_auth = no
    listen = *, ::
    !include_try /usr/share/dovecot/protocols.d/imapd.protocol
sudo nano /etc/dovecot/conf.d/10-ssl.conf
    ssl = no
    #ssl_cert = </etc/dovecot/dovecot.pem
    #ssl_key = </etc/dovecot/private/dovecot.pem
sudo start dovecot
ps -A | grep dovecot
@itsazzad
Copy link

  • [x]

@Serkan-devel
Copy link

There is also a repo which contains self-hosted email server software written in ruby on rails https://github.com/mlandauer/cuttlefish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment