How to create mail server in centos 7

Creating a mail server in CentOS 7 involves several steps, including installing and configuring the necessary software, setting up the mail server's configuration files, and configuring the firewall. Here's a step-by-step guide to help you create a mail server in CentOS 7:

Step 1: Install the necessary software

You'll need to install the following packages:

Run the following command to install the packages:

sudo yum install postfix dovecot mysql-server courier

Step 2: Configure Postfix

Postfix is the mail transfer agent that will handle the sending and receiving of emails. You'll need to configure it to use the MySQL database and to allow relaying.

Edit the Postfix configuration file:

sudo nano /etc/postfix/main.cf

Add the following lines to the end of the file:

mydestination = localhost
myhostname = mail.example.com
myorigin = $myhostname
mynetworks = 127.0.0.0/8 [::1]/128
relayhost =
inet_interfaces = all

Replace mail.example.com with your mail server's hostname.

Step 3: Configure Dovecot

Dovecot is the IMAP/POP3 server that will handle email retrieval. You'll need to configure it to use the MySQL database and to allow authentication.

Edit the Dovecot configuration file:

sudo nano /etc/dovecot/dovecot.conf

Add the following lines to the end of the file:

auth_username_format = %n
auth_mechanisms = plain login
mail_location = maildir:~/Maildir

Step 4: Configure MySQL

MySQL is the database server that will store the mail server's configuration and user data. You'll need to create a database and a user for the mail server.

Create a new database:

sudo mysql -u root -p

Create a new database:

CREATE DATABASE mail;

Create a new user:

CREATE USER 'mailuser'@'localhost' IDENTIFIED BY 'password';

Grant the user permissions:

GRANT ALL PRIVILEGES ON mail.* TO 'mailuser'@'localhost';

Step 5: Configure Courier

Courier is the authentication server that will handle user authentication. You'll need to configure it to use the MySQL database.

Edit the Courier configuration file:

sudo nano /etc/courier/authmysqlrc

Add the following lines to the end of the file:

MYSQL_SERVER localhost
MYSQL_USERNAME mailuser
MYSQL_PASSWORD password
MYSQL_DB mail

Step 6: Configure the firewall

You'll need to configure the firewall to allow incoming connections to the mail server.

Edit the firewall configuration file:

sudo nano /etc/sysconfig/ip6tables

Add the following lines to the end of the file:

-A INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 587 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 993 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 995 -j ACCEPT

Step 7: Start the services

Start the Postfix, Dovecot, and Courier services:

sudo systemctl start postfix
sudo systemctl start dovecot
sudo systemctl start courier

Step 8: Test the mail server

You can test the mail server by sending an email to a user on the mail server. You can use the telnet command to test the mail server:

telnet mail.example.com 25

Replace mail.example.com with your mail server's hostname.

That's it! You've now created a mail server in CentOS 7. You can use the mail server to send and receive emails using a mail client such as Thunderbird or Outlook.