- Problem definition
- Requirements
-
Part I : Postfix configuration
- Add a mail server to your DNS
- Install the Postfix server(SMTP)
- Check the repository /etc/postfix and identify the configuration files.
- Explain the role of the main.cf configuration file.
- Explain the role of the master.cf configuration file.
- Create a database (in mysql database) which will correspond and interact with Postfix.
- Create users that will be associated with this database.
- Install the Dovecote (POP3/IMAP).
- Test configuration with a mail client (telnet, thunderbird).
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.
- Linux,
- Mysql,
- Postfix,
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.
Now enter the fully qualified domain name that you want to use for send and receive emails. In our case, it is ataman.me
.
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
This is the architecture of the data base that we will create :
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
MYSQL server is ready
mysql
We have already create the database (mailserver) :
Now we will connect to the (mailserver) DB, and those are the table created :
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 :
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
Now for the configuration of Dovecot server :
cd /etc/dovecot
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
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 :
Then we will use dovecot to login and check if the message is in the mailbox :
retr 6.. number 6 is the 6th message sent ( yes they were 5 tests before :| )
Everything is working just FIIIINE -__-
Out Team - AIT EL KADI Ilyas - AZIZ Oussama
Project Link: https://github.com/IlyasKadi/Postfix-mail-Server