How to Install Mail Server on Ubuntu 16.04(Part 1) ( Dovecot – Postfix – Roundcube )

ubuntu-mailserver

You can setup your full(receiving and sending) mail server on Ubuntu using multiple software’s ie. Postfix, Dovecot and Roundcube. To receive your mails on Ubuntu server you need Dovecot, to send email from your server you need Postfix and to access your mail using web client you need Roundcube, you can also access your mails using third party clients like Thunderbird.

Prerequisites : Install LAMP server on Ubuntu

Step 1. Login to your linux machine.

Step 2. Install Packages for Postfix & Dovecot.

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

Select configuration type Internet Site:

internet-site

Specify your fully qualified domain name(FDQN):

Step 3. Login into your Mysql Server.

# mysql -u root -p

Step 4. Create a new database for mailserver.

# create database servermail;

Step 5. Create a user for mysql & grant select privileges to that user with your desired password.

# GRANT SELECT ON servermail.* TO 'mailuser'@'127.0.0.1' IDENTIFIED BY 'mailuserpasswd';

Step 6. Flush privileges to apply changes.

# FLUSH PRIVILEGES;

Step 7. Use servermail database for creating tables.

# use servermail;

Step 8. Create a tables for mailserver.

Create a table for domain that will receive mail:

# CREATE TABLE  `virtual_domains` (
`id` int(10) NOT NULL auto_increment,
`name` varchar(40) NOT NULL,
PRIMARY KEY (`id`) )
ENGINE=InnoDB DEFAULT CHARSET=utf8;

Create a table to add Email address & Password:

# CREATE TABLE `virtual_users` ( 
`id` INT NOT NULL AUTO_INCREMENT, 
`domain_id` INT NOT NULL, 
`password` varchar(106) NOT NULL, 
`email` varchar(120) NOT NULL, 
PRIMARY KEY (`id`), 
UNIQUE KEY `email` (`email`) ) 
ENGINE=InnoDB DEFAULT CHARSET=utf8;

Create a table to add virtual aliases:

# CREATE TABLE `virtual_aliases` ( 
`id` INT NOT NULL AUTO_INCREMENT, 
`domain_id` INT NOT NULL, 
`source` varchar(100) NOT NULL, 
`destination` varchar(100) NOT NULL, 
PRIMARY KEY (`id`) ) 
ENGINE=InnoDB DEFAULT CHARSET=utf8;

Step 9. Adding data into tables.

Adding domains in virtual_domain table & make sure to replace examplenet.xyz with your domain name:

# INSERT INTO `servermail`.`virtual_domains`
(`id` , `name`)
VALUES
('1', 'examplenet.xyz');

Adding email address in virtual_users table.Make sure to replace domain name & mailuserpassword with your settings:

# INSERT INTO `servermail`.`virtual_users`
(`id` , `domain_id` , `password` , `email`)
VALUES
('1', '1', MD5('mailuserpasswd'), '[email protected]xamplenet.xyz');

Adding Email Alias in Virtual_aliases table:

# INSERT INTO `servermail`.`virtual_aliases`
(`id`, `domain_id`, `source`, `destination`)
VALUES
('1', '1', '[email protected]', '[email protected]');

Step 10. Now we are going to test contents of every servermail tables.

Test the content of virtual_domain table:

# select * from servermail.virtual_domains;

Test the content of virtual_users table:

# select * from servermail.virtual_users;

Test the content of virtual_aliases table:

# select * from servermail.virtual_aliases;

Step 11. Exit from Mysql.

# exit

Click below link to see further Installation & Configuration of Mail Server:

How to Install Mail Server on Ubuntu 16.04(Part 2) ( Dovecot – Postfix – Roundcube )