mail server on centos 7

----@- dhA -@-----

[root@mail ~]# useradd -m u1 -s /sbin/nologin

[root@mail ~]# passwd u1

useradd -m -p 4w5yRzfvfQFAI -s /sbin/nologin u1

useradd -m -p 4w5yRzfvfQFAI -s /sbin/nologin u2

useradd -m -p 4w5yRzfvfQFAI -s /sbin/nologin virusalert

useradd -m -p 4w5yRzfvfQFAI -s /sbin/nologin virusmails

useradd -m -p 4w5yRzfvfQFAI -s /sbin/nologin spamalert

useradd -m -p 4w5yRzfvfQFAI -s /sbin/nologin spam.police

useradd -m -p 4w5yRzfvfQFAI -s /sbin/nologin sys_admin

useradd -m -p 4w5yRzfvfQFAI -s /sbin/nologin inmail

useradd -m -p 4w5yRzfvfQFAI -s /sbin/nologin outmail

useradd -m -p 4w5yRzfvfQFAI -s /sbin/nologin junkmail

Setup mail server on centos 7

1. Remove default MTA sendmail first if it’s already installed. Sendmail will not be installed by default in minimal installation, so you can skip this step.

yum remove sendmail

2. Setup DNS server and add the Mail server MX records in the forward and reverse zone files.

To install and configure DNS server, refer the following link.

And, don’t forget to ask your ISP to point your external static IP to your mail domain.

3. Add hostname entries in /etc/hosts file as shown below:

vi /etc/hosts

Add your FQDN:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.150 server1.unixmen.local server1

4. I disabled SELinux to reduce the complexity in postfix configuration.

To do that, edit:

vi /etc/sysconfig/selinux

Change SELINUX=enforcing to SELINUX=disabled.

SELINUX=disabled

5. Install EPEL Repository:

Squirrelmail webmail client is not available in CentOS official repositories. So let us enable EPEL repository.

yum install epel-release

6. Allow the Apache default port 80 through your firewall/router:

firewall-cmd --permanent --add-port=80/tcp

Restart firewall using command:

firewall-cmd --reload

Restart your server to take effect all changes.

I

Now, log out from user “senthil“ and log in to user “kumar“ mail and check for any new mail.

Hurrah! We have got a new mail from senthil@unixmen.local mail id.

To read the mail, click on it. You’ll now be able to read, reply, delete or compose a new mail.

That’s all for now. We’ve successfully configured a local mail server that will serve in/out mails within a local area network.

Hope this tutorial will help you.

Good luck!

#######################################################################

Postfix With Data base Configuration 

1. Installing packages

2. Postfix configuration

3. Dovecot configuration

4. User creation

Installing packages

Step 1 » Assign hostname for the server using the below command.

[root@krizna ~]# hostnamectl set-hostname mail.krizna.com

Step 2 » Make a host entry with your IP in /etc/hosts file.

172.27.0.51 mail.krizna.com

Step 3 » Now start installing packages.

[root@krizna ~]# yum -y install postfix dovecot

After package installation continue with postfix configuration.

Postfix configuration

First create SSL certificate for encryption.

Step 4 » Follow the below steps one by one for creation.

[root@mail ~]# mkdir /etc/postfix/ssl

[root@mail ~]# cd /etc/postfix/ssl

[root@krizna ssl]# openssl genrsa -des3 -out server.key 2048

[root@krizna ssl]# openssl rsa -in server.key -out server.key.insecure

[root@krizna ssl]# mv server.key server.key.secure

[root@krizna ssl]# mv server.key.insecure server.keyLeave blank for A challenge password [] value in the below step.

[root@krizna ssl]# openssl req -new -key server.key -out server.csr

[root@krizna ssl]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Country Name (2 letter code) [XX]:BD

State or Province Name (full name) []:Dhaka

Locality Name (eg, city) [Default City]:Dhaka

Organization Name (eg, company) [Default Company Ltd]:World Communication Network Ltd.

Organizational Unit Name (eg, section) []:worldcm.net

Common Name (eg, your name or your server's hostname) []:mail.worldcm.net

Email Address []: admin@worldcm.net

A challenge password []:world

An optional company name []: worldcm

An optional company name []: worldcmStep 5 » Now open /etc/postfix/main.cf file for changes.

Find and uncomment the below lines.

#inet_interfaces = localhost #---> line no 116

#mydestination = $myhostname, localhost.$mydomain, localhost #--> line no 164 

and add below lines at the end of the file. change myhostname andmydomain values with yours and home_mailbox value to your desired directory. Here it will store mails in the users home directory (Eg: /home/john/mail ).

myhostname = mail.krizna.com

mydomain = krizna.com

myorigin = $mydomain

home_mailbox = mail/

mynetworks = 127.0.0.0/8

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

smtpd_sasl_type = dovecot

smtpd_sasl_path = private/auth

smtpd_sasl_local_domain =

smtpd_sasl_security_options = noanonymous

broken_sasl_auth_clients = yes

smtpd_sasl_auth_enable = yes

smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination

smtp_tls_security_level = may

smtpd_tls_security_level = may

smtp_tls_note_starttls_offer = yes

smtpd_tls_loglevel = 1

smtpd_tls_key_file = /etc/postfix/ssl/server.key

smtpd_tls_cert_file = /etc/postfix/ssl/server.crt

smtpd_tls_received_header = yes

smtpd_tls_session_cache_timeout = 3600s

tls_random_source = dev:/dev/urandom

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

myhostname = mail.krizna.com

mydomain = krizna.com

myorigin = $mydomain

home_mailbox = mail/

mynetworks = 127.0.0.0/8

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain

smtpd_sasl_type = dovecot

smtpd_sasl_path = private/auth

smtpd_sasl_local_domain =

smtpd_sasl_security_options = noanonymous

broken_sasl_auth_clients = yes

smtpd_sasl_auth_enable = yes

smtpd_recipient_restrictions =permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination

smtp_tls_security_level = may

smtpd_tls_security_level = may

smtp_tls_note_starttls_offer = yes

smtpd_tls_loglevel = 1

smtpd_tls_key_file = /etc/postfix/ssl/server.key

smtpd_tls_cert_file = /etc/postfix/ssl/server.crt

smtpd_tls_received_header = yes

smtpd_tls_session_cache_timeout = 3600s

tls_random_source = dev:/dev/urandom

Step 6 » Open /etc/postfix/master.cf file, add the below lines after “smtp inet n – n – – smtpd” line.

submission inet n – n – – smtpd

-o syslog_name=postfix/submission

-o smtpd_sasl_auth_enable=yes

-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject

-o milter_macro_daemon_name=ORIGINATING

smtps inet n – n – – smtpd

-o syslog_name=postfix/smtps

-o smtpd_sasl_auth_enable=yes

-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject

-o milter_macro_daemon_name=ORIGINATING

1

2

3

4

5

6

7

8

9

10

submission     inet  n       –       n       –       –       smtpd

  –o syslog_name=postfix/submission

  –o smtpd_sasl_auth_enable=yes

  –osmtpd_recipient_restrictions=permit_sasl_authenticated,reject

  –o milter_macro_daemon_name=ORIGINATING

smtps     inet  n       –       n       –       –       smtpd

  –o syslog_name=postfix/smtps

  –o smtpd_sasl_auth_enable=yes

  –osmtpd_recipient_restrictions=permit_sasl_authenticated,reject

  –o milter_macro_daemon_name=ORIGINATING

Now check the configuration using postfix check command.

Step 7 » Now configure Dovecot SASL for SMTP Auth. Open/etc/dovecot/conf.d/10-master.conf file, find “# Postfix smtp-auth” line ( line no:95 ) and add the below lines.

# Postfix smtp-auth

unix_listener /var/spool/postfix/private/auth {

mode = 0660

user = postfix

group = postfix

}

Step 8 » Open /etc/dovecot/conf.d/10-auth.conf file, find “auth_mechanisms = plain” ( Line no: 100 ) and add login to the value like below.

auth_mechanisms = plain login

Step 9 » Postfix configuration is over. Now restart both postfix and dovecot services and enable auto start.

[root@mail ~]# systemctl restart postfix

[root@mail ~]# systemctl enable postfix

[root@mail ~]# systemctl restart dovecot

[root@mail ~]# systemctl enable dovecot

Step 10 » Add the firewall rules to allow 25, 587 and 465 ports.

[root@mail ~]# firewall-cmd --permanent --add-service=smtp

[root@mail ~]# firewall-cmd --permanent --add-port=587/tcp

[root@mail ~]# firewall-cmd --permanent --add-port=465/tcp

[root@mail ~]# firewall-cmd --reloadNow start testing connectivity for each ports 25,587 and 465 using telnet and make sure you are getting AUTH PLAIN LOGIN line after issuing ehlo mail.krizna.com command in telnet.

[root@mail ~]# telnet mail.krizna.com 465

Trying 172.27.0.51...

Connected to mail.krizna.com.

Escape character is '^]'.

220 mail.krizna.com ESMTP Postfix

ehlo mail.krizna.com <------- Type this command

250-mail.krizna.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-STARTTLS

250-AUTH PLAIN LOGIN

250-AUTH=PLAIN LOGIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

Dovecot configuration

Start configuring Dovecot .

Step 11 » Open /etc/dovecot/conf.d/10-mail.conf file, find#mail_location = (line no : 30 ) and add the same directory which is given tohome_mailbox in the postfix config file ( Step 5).

mail_location = maildir:~/mail

Step 12 » Open /etc/dovecot/conf.d/20-pop3.conf file, find and uncomment the below line ( line no : 50 ) .

pop3_uidl_format = %08Xu%08Xv

Step 13 » Restart dovecot service.

[root@mail ~]# systemctl restart dovecot

Step 14 » Add firewall rules to allow 110,143,993 and 995.

[root@mail ~]# firewall-cmd --permanent --add-port=110/tcp

[root@mail ~]# firewall-cmd --permanent --add-service=pop3s

[root@mail ~]# firewall-cmd --permanent --add-port=143/tcp

[root@mail ~]# firewall-cmd --permanent --add-service=imaps

[root@mail ~]# firewall-cmd --reload

Check the connectivity for the ports 110,143,993 and 995 using telnet.

User creation

Now create user for testing .

Step 15 » Create user with /sbin/nologin shell to restrict login access.

[root@mail ~]# useradd -m john -s /sbin/nologin

[root@mail ~]# passwd john

Mail server is ready now, Configure user in your mail client and test send/receive.

Email with Postfix, Dovecot and MariaDB on CentOS 7

The Postfix Mail Transfer Agent (MTA) is a high performance open source e-mail server system. This guide will help you get Postfix running on your CentOS 7 Linode, using Dovecot for IMAP/POP3 service, and MariaDB, a drop-in replacement for MySQL, to store information on virtual domains and users.

Prior to using this guide, be sure you have followed the getting started guideand set your hostname. Also ensure that the iptables firewall is not blocking any of the standard mail ports (25, 465, 587, 110, 995, 143, and 993). If using a different form of firewall, confirm that it is not blocking any of the needed ports either.

The steps in this guide require root privileges. Be sure to run the steps below as root or with the sudo prefix. For more information on privileges see our Users and Groupsguide.

Install Required Packages

Next, set up a MariaDB database to handle virtual domains and users.

Set up MariaDB for Virtual Domains and Users

Next, perform additional Postfix configuration to set up communication with the database.

Configure Postfix to work with MariaDB

For the next four steps, replace mail_admin_password with themail_admin password input earlier.

This completes the configuration for Postfix.

Configure Dovecot

Configure Mail Aliases

This completes alias configuration. Next, test Postfix to make sure it’s operating properly.

Testing Postfix

Next, populate the MariaDB database with domains and email users.

Set Up and Test Domains and Users

Before continuing, modify the DNS records for any domains that you wish to handle email by adding an MX record that points to your mail server’s fully qualified domain name. If MX records already exist for a domain you would like to handle the email for, either delete them or set them to a higher priority number than your mail server. Smaller priority numbers indicate higher priority for mail delivery, with “0” being the highest priority.

In the following example, the MariaDB shell is used to add support for the domain “example.com”, which will have an email account called “sales”.

Given the possibility for virtual hosting a large number of virtual domains on a single mail system, the username portion of an email address (i.e. before the @ sign) is not sufficient to authenticate to the mail server. When email users authenticate to the server, they must supply their email clients with the entire email address created above as their username.

Check Your Logs

After the test mail is sent, check the mail logs to make sure the mail was delivered.

Now you can test to see what the users of your email server would see with their email clients.

Test the Mailbox

https://nazimkuet.wordpress.com/2015/08/26/setup-mail-server-on-centos-7-email-with-postfix-dovecot-and-mariadb-on-centos-7/

################################################################################################################

his article helps you to install and configure basic mail server on Centos 7. Here i have used Postfix for SMTP, Dovecot for POP/IMAP and Dovecot SASL for SMTP AUTH.

Before proceeding please make sure you have assigned static IP for the server and have internet connectivity for installing packages.

Setup mail server on centos 7

1. Installing packages

2. Postfix configuration

3. Dovecot configuration

4. User creation

Installing packages

Step 1 » Assign hostname for the server using the below command.

[root@krizna ~]# hostnamectl set-hostname mail.krizna.com

Step 2 » Make a host entry with your IP in /etc/hosts file.

172.27.0.51 mail.krizna.com

Step 3 » Now start installing packages.

[root@krizna ~]# yum -y install postfix dovecot

After package installation continue with postfix configuration.

Postfix configuration

First create SSL certificate for encryption.

Step 4 » Follow the below steps one by one for creation.

[root@mail ~]# mkdir /etc/postfix/ssl

[root@mail ~]# cd /etc/postfix/ssl

[root@krizna ssl]# openssl genrsa -des3 -out server.key 2048

[root@krizna ssl]# openssl rsa -in server.key -out server.key.insecure

[root@krizna ssl]# mv server.key server.key.secure

[root@krizna ssl]# mv server.key.insecure server.key

Leave blank for A challenge password [] value in the below step.

[root@krizna ssl]# openssl req -new -key server.key -out server.csr

[root@krizna ssl]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Step 5 » Now open /etc/postfix/main.cf file for changes.

Find and uncomment the below lines.

#inet_interfaces = localhost #---> line no 116

#mydestination = $myhostname, localhost.$mydomain, localhost #--> line no 164

and add below lines at the end of the file. change myhostname and mydomainvalues with yours and home_mailbox value to your desired directory. Here it will store mails in the users home directory (Eg: /home/john/mail ).

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

myhostname = mail.krizna.com

mydomain = krizna.com

myorigin = $mydomain

home_mailbox = mail/

mynetworks = 127.0.0.0/8

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

smtpd_sasl_type = dovecot

smtpd_sasl_path = private/auth

smtpd_sasl_local_domain =

smtpd_sasl_security_options = noanonymous

broken_sasl_auth_clients = yes

smtpd_sasl_auth_enable = yes

smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination

smtp_tls_security_level = may

smtpd_tls_security_level = may

smtp_tls_note_starttls_offer = yes

smtpd_tls_loglevel = 1

smtpd_tls_key_file = /etc/postfix/ssl/server.key

smtpd_tls_cert_file = /etc/postfix/ssl/server.crt

smtpd_tls_received_header = yessmtpd_tls_session_cache_timeout = 3600s

tls_random_source = dev:/dev/urandom

Step 6 » Open /etc/postfix/master.cf file, add the below lines after “smtp inet n – n – – smtpd” line.

1

2

3

4

5

6

7

8

9

10

submission     inet  n       -       n       -       -       smtpd

  -o syslog_name=postfix/submission

  -o smtpd_sasl_auth_enable=yes

  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject

  -o milter_macro_daemon_name=ORIGINATING

smtps     inet  n       -       n       -       -       smtpd

  -o syslog_name=postfix/smtps

  -o smtpd_sasl_auth_enable=yes

  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject

  -o milter_macro_daemon_name=ORIGINATING

Now check the configuration using postfix check command.

Step 7 » Now configure Dovecot SASL for SMTP Auth. Open /etc/dovecot/conf.d/10-master.conf file, find “# Postfix smtp-auth” line ( line no:95 ) and add the below lines.

# Postfix smtp-auth

unix_listener /var/spool/postfix/private/auth {

mode = 0660

user = postfix

group = postfix

}

Step 8 » Open /etc/dovecot/conf.d/10-auth.conf file, find “auth_mechanisms = plain” ( Line no: 100 ) and add login to the value like below.

auth_mechanisms = plain login

Step 9 » Postfix configuration is over. Now restart both postfix and dovecot services and enable auto start.

[root@mail ~]# systemctl restart postfix

[root@mail ~]# systemctl enable postfix

[root@mail ~]# systemctl restart dovecot

[root@mail ~]# systemctl enable dovecot

Step 10 » Add the firewall rules to allow 25, 587 and 465 ports.

[root@mail ~]# firewall-cmd --permanent --add-service=smtp

[root@mail ~]# firewall-cmd --permanent --add-port=587/tcp

[root@mail ~]# firewall-cmd --permanent --add-port=465/tcp

[root@mail ~]# firewall-cmd --reload

Now start testing connectivity for each ports 25,587 and 465 using telnet and make sure you are getting AUTH PLAIN LOGIN line after issuing ehlo mail.krizna.comcommand in telnet.

[root@mail ~]# telnet mail.krizna.com 465

Trying 172.27.0.51...

Connected to mail.krizna.com.

Escape character is '^]'.

220 mail.krizna.com ESMTP Postfix

ehlo mail.krizna.com <------- Type this command

250-mail.krizna.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-STARTTLS

250-AUTH PLAIN LOGIN

250-AUTH=PLAIN LOGIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

Dovecot configuration

Start configuring Dovecot .

Step 11 » Open /etc/dovecot/conf.d/10-mail.conf file, find #mail_location = (line no : 30 ) and add the same directory which is given to home_mailbox in the postfix config file ( Step 5).

mail_location = maildir:~/mail

Step 12 » Open /etc/dovecot/conf.d/20-pop3.conf file, find and uncomment the below line ( line no : 50 ) .

pop3_uidl_format = %08Xu%08Xv

Step 13 » Restart dovecot service.

[root@mail ~]# systemctl restart dovecot

Step 14 » Add firewall rules to allow 110,143,993 and 995.

[root@mail ~]# firewall-cmd --permanent --add-port=110/tcp

[root@mail ~]# firewall-cmd --permanent --add-service=pop3s

[root@mail ~]# firewall-cmd --permanent --add-port=143/tcp

[root@mail ~]# firewall-cmd --permanent --add-service=imaps

[root@mail ~]# firewall-cmd --reload

Check the connectivity for the ports 110,143,993 and 995 using telnet.

User creation

Now create user for testing .

Step 15 » Create user with /sbin/nologin shell to restrict login access.

[root@mail ~]# useradd -m john -s /sbin/nologin

[root@mail ~]# passwd john

Mail server is ready now, Configure user in your mail client and test send/receive.