IlyasKadi / Postfix-mail-Server

Postfix is a mail transfer agent (MTA), an application used to send and receive email.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Logo

Project 4

Postfix mail server

Table of Contents
  1. Problem definition
  2. Requirements
  3. Part I : Postfix configuration

Problem definition:

The electronic mail, e-mail or email, is a service for the transmission of messages sent electronically via a computer network to the electronic mailbox of a recipient chosen by the sender.

Postfix is a popular open-source Mail Transfer Agent (MTA) that can be used to route and deliver email on a Linux system. Several enterprises desire to use their own mail server for different purposes. Whether it is for security purposes or to be able to exchange messages locally, Postfix is always a fitting solution.

Requirements

  • Linux,
  • Mysql,
  • Postfix,

Part-I

addition-the-mail-server-to-the-dns

Installation-the-Postfix-server

sudo apt-get install postfix

During installation, you will be asked to choose the type of mail configuration, choose “Internet Site”.

We can select the No configuration option if we want to keep the default Postfix settings. The Internet site allows us to send and receive emails using SMTP. Therefore, we select the second option as shown in the following screenshot.

postfix__i

Now enter the fully qualified domain name that you want to use for send and receive emails. In our case, it is ataman.me.

post_ataman

Once Postfix installed, it will automatically start and creates a new /etc/postfix/main.cf file. You can verify the status of the service using the following commands.

sudo systemctl status postfix

postfix_status

Checking-the-repository-and-identification-of-the-configuration-files

role-of-main-cf

main_cf__1

role-of-master-cf

Creation-of-the-database

This is the architecture of the data base that we will create :

DBdesugn

Let's first restart mysqlserver (if it exists of course otherwise an installation is required).

sudo apt-get install mysql-server 
systemctl restart mysql

Checking the server

systemctl status mysql

db_status

MYSQL server is ready

mysql

mariadb

We have already create the database (mailserver) :

mailserver_db_shown

Now we will connect to the (mailserver) DB, and those are the table created :

mailserver_tables

Creation-of-the-users

This is the code for the table of the users

CREATE TABLE virtual_Users (
	domain_name VARCHAR(100) not null,
	email VARCHAR(100) NOT NULL,
	password VARCHAR(106) NOT NULL,
	fullname VARCHAR(50) NOT NULL,
	department VARCHAR(50) NOT NULL,
	status_id INT NOT NULL DEFAULT 1,
PRIMARY KEY (email),
FOREIGN KEY (domain_name) REFERENCES virtual_Domains(domain_name) ON DELETE CASCADE,
FOREIGN KEY (status_id) REFERENCES virtual_Status(status_id) ON DELETE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

Then we will ad two users: oussama & ilyas, and for the password it is encrypted with a Secure Hash Algorithm : SHA2.

INSERT INTO virtual_Users (domain_name,email,password,fullname,department) VALUES ('hvthang.xyz','test1@hvthang.xyz',TO_BASE64(UNHEX(SHA2('test1', 512))),'Test 1','Test');

INSERT INTO virtual_Users (domain_name,email,password,fullname,department) VALUES ('hvthang.xyz','test2@hvthang.xyz',TO_BASE64(UNHEX(SHA2('test2', 512))),'Test 2','Test');

UNHEX() function performs the opposite operation of HEX() wich returns a string representation of a hexadecimal value of a decimal or string value specified as an argument.

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs be stored and transferred over media that are designed to deal with textual data.

Users_table :

users_table

Installation-of-dovecot-pop-imap

To install Dovecot and its modules :

apt install dovecot-core dovecot-imapd dovecot-pop3 dovecot-lmtpd dovecot-mysql-y
systemctl start dovecot
systemctl status dovecot

dovecot_status

Now for the configuration of Dovecot server :

cd /etc/dovecot
ls

etc_dov_ls

In the conf-file dovecot.conf: We will add the protocols imap pop3 lmtp (Local Mail Transfer Protocol (LMTP) is an alternative to (Extended) Simple Mail Transfer Protocol)

# Enable installed protocols
!include_try /usr/share/dovecot/protocols.d/*.protocol
protocols = imap pop3 lmtp

In the conf file dovecot-sql.conf.ext: We will add the driver and we will connect this file to the mailserver DB that we created before, and we will specify the password query and the format in which the password is stored in pssds database for the query:

driver = mysql
connnect = host=127.0.0.1 dbname =mailserver user =mailuser password=2445
password_query = SELECT email as user,  password FROM virtual_Users WHERE email='%u' and status_id=1;
defaukt_pass_shceme = SHA512

We wil add serveral settings to the dovecot conf files to link between all the configs together.

Next we are going enable smpt for authenticated users and authentication to dovecot in the main_conf file of postfix server main.cf in etc/postfix

smtp_sasl_type = dovecot
smtp_sasl_path = private/auth
smtp_sasl_auth_enable = yes
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes

We're almost there all we need is to restart the postfix and the dovcecot servers

systemctl restart dovecot
systemctl restart postfix

And last but not least we make sure that ufw is disabled otherwise we aloow the port 25,110 and 145 for SMTP,POP and IMAP

Test-the-configuration

To test if everything is OK, we will use telnet to send a mail from one user to another: First we are going use SMTP to send a message :

telnet_25

Then we will use dovecot to login and check if the message is in the mailbox :

ehlo_ouss_to_ilyas

retr 6.. number 6 is the 6th message sent ( yes they were 5 tests before :| )

Everything is working just FIIIINE -__-

(back to top)

Out Team - AIT EL KADI Ilyas - AZIZ Oussama

Project Link: https://github.com/IlyasKadi/Postfix-mail-Server

(back to top)

About

Postfix is a mail transfer agent (MTA), an application used to send and receive email.