Self-Host an Email Server (Not finished)

You are going to learn how to configure a mail server on Ubuntu using Postfix, Dovecot, and MySQL.
You will need a server for this, my recommendation is SysKiller VPS.
Create a LEMP stack server, which is based on Ubuntu 16.04 LTS, and login via ssh.
Now configure DNS records for your domain, replacing ‘0.0.0.0’ with your server IP.

Show content

example.com A 10 0.0.0.0
example.com MX 10 example.com
mail.example.com MX 10 example.com

[collapse]

Ensure that the MX record is changed for all domains and subdomains that might receive email.
Now we need to install an ssl certificate.
It is recommended to purchase a commercial certificate, but Let’s Encrypt will work fine.
The next steps are to install packages on your server.
Show code

apt-get install postfix postfix-mysql dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql

[collapse]

Select ‘Internet Site’ for postfix configuration.
System mail name should be your server’s FQDN.
The mysql server installed in to the lamp stack has the default root password as ‘root’, which you must change.
After that, you need to create a user for your mail server.
Show code

mysqladmin -p create mailserver

[collapse]

Now enter your root password.
Login to your mailserver user:
Show code

mysql -p mailserver

[collapse]

Create the mysql user and grant the new user permissions over the database. Replace ‘password’ with a strong password.
Show code

GRANT SELECT ON mailserver.* TO 'mailuser'@'127.0.0.1' IDENTIFIED BY 'password'

[collapse]

Flush the privileges to apply changes:
Show code

FLUSH PRIVILEGES;

[collapse]

Create a table for all domains that may receive email from this server:
Show code

CREATE TABLE 'virtual_domains' (
'id' int(11) NOT NULL auto_increment,
'name' varchar(50) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

[collapse]

Create a database for all of the email addresses and passwords:
Show code

16. CREATE TABLE `virtual_users` (
'id' int(11) NOT NULL auto_increment,
'domain_id' int(11) NOT NULL,
'password' varchar(106) NOT NULL,
'email' varchar(100) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE KEY 'email' ('email'),
FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

[collapse]

Create a table for email aliases:

One thought on “Self-Host an Email Server (Not finished)

  1. Hi there,I log on to your new stuff named “Self-Host an Email Server (Not finished) – HackerMatrix” daily.Your humoristic style is awesome, keep doing what you’re doing! And you can look our website about free proxy.

Leave a Reply

Your email address will not be published. Required fields are marked *