0% found this document useful (0 votes)
86 views

TP Mail

This document provides instructions for installing and configuring a basic email server on CentOS 7 using Postfix as the mail transfer agent (MTA) and Dovecot for mail delivery. The steps include: 1) Creating user accounts for testing email 2) Installing Postfix and configuring firewall rules to allow access to SMTP, POP3, and IMAP ports 3) Configuring Postfix settings such as the hostname, domain name, and network interfaces in main.cf 4) Starting the Postfix service and enabling it to start at boot 5) Testing the Postfix configuration using Telnet The goal is to set up a basic but functional email server for internal use with a domain like esp

Uploaded by

Skander Guermazi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

TP Mail

This document provides instructions for installing and configuring a basic email server on CentOS 7 using Postfix as the mail transfer agent (MTA) and Dovecot for mail delivery. The steps include: 1) Creating user accounts for testing email 2) Installing Postfix and configuring firewall rules to allow access to SMTP, POP3, and IMAP ports 3) Configuring Postfix settings such as the hostname, domain name, and network interfaces in main.cf 4) Starting the Postfix service and enabling it to start at boot 5) Testing the Postfix configuration using Telnet The goal is to set up a basic but functional email server for internal use with a domain like esp

Uploaded by

Skander Guermazi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CentOS 7 –install & configure

Postfix – Dovecot
Services et Administration des Réseaux

Esprit 2021/2022
CentOS 7 –install & configure Postfix – Dovecot
Services et Administration des Réseaux

Introduction:
There are many different scenarios and combinations that can be used when setting up an email
server (far to many to cover here), so this TP makes some basic choices for you, such as the
software we will use (postfix and dovecot). Other options are required to be altered by the user,
such as your network addresses and domain names.

This TP uses postfix as the mail transport agent (MTA), as opposed to sendmail, the default MTA
for CentOS 5 (postfix is the default in CentOS 6). Dovecot is used to allow users to access their
email by either imap or pop protocols. We assume a domain name of esprit.com which should
be changed by the reader and can be either a real domain name for a fully qualified email server
or a fake domain name if you only wish to implement an internal mail server.

Objectifs:
✓ Add user accounts (user1 and unser2).
✓ Installing the MTA and MDA services.
✓ Configuring Postfix and Dovecot software module.
✓ Testing

Step 1 : Creating the users


CentOS 7 –install & configure Postfix – Dovecot |

Create the first user:

#useradd –m user1
#passwd user1

Create the second user:

#useradd –m user2
#passwd user2

1
Step 2 : Install Postfix server

Before installing postfix, you should check if it is already installed because postfix is the
default MTA in CentOS 7. But if Postfix is not, use the below command to install it
[root@server ~]# yum -y install postfix

Step 3 : Configuring iptables

By default Port number 25, 110 and 143 are closed so we need to allow access throw those
ports

Configuring the Firewall:

Enabling access on port SMPT (tcp/25), POP3 (tcp/110), and IMAP (tcp/143) in the iptables.

Edit the iptable configuration file:

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

[root@dlp ~]# firewall-cmd --add-service={pop3,imap} --permanent

[root@dlp ~]# firewall-cmd –reload


CentOS 7 –install & configure Postfix – Dovecot |

Step 4 : Configuring Postfix

Open the postfix config file /etc/postfix/main.cf. Find the below lines and edit them as shown
below.
[root@server ~]# nano /etc/postfix/main.cf

# line 75 uncomment and enter your hostname


myhostname = mail.esprit.com
#line no 83 - uncomment and enter your domain name
mydomain = esprit.com

#line no 99 - uncomment
myorigin = $mydomain

# line 116 change to all


inet_interfaces = all

#line no 164 - add $domain at the end


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

#line no 264 - uncomment and add your network range


mynetworks = 192.168.1.0/24, 127.0.0.0/8

#line no 419 - uncomment


home_mailbox = Maildir/

Now let’s take a look at each setting it turn to understand what we've just done:

myhostname: is the host name of the system ( the system is called mail or mail.esprit.com).

mydomain: is the domain name for the email server (it can be a real or fake domain name).

myorigin: is the domain name that locally-posted email appears to have come from and is
delivered to.

inet_interfaces: sets the network interfaces that Postfix can receive mail on. These need to
include at least localhost and the local domain.

mydestination: is the list of domains that will be delivered to ( this server is the final
destination for email addressed to these domains).

mynetworks: is a list of trusted IP addresses that may send or relay mail through the server.
CentOS 7 –install & configure Postfix – Dovecot |

Users attempting to send email through the server originating from IP addresses not listed
here will be rejected.

relay_domains: is a list of destination domains this system will relay mail to. By setting it to
be blank we ensure that our mail server isn't acting as an open relay for untrusted networks.

home_mailbox: sets the path of the mailbox relative to the users home directory and also
specifies the style of mailbox to be used. Postfix supports both Maildir and mbox formats and
readers are encouraged to read up on the merits of each for themselves.

3
Step 5 : Start the services

After finishing the configuration we should start the service and keep it on

[root@server ~]# systemctl restart postfix

[root@server ~]# systemctl enable postfix

Step 6 : Test Postfix using the command telnet

The commands shown in bold letters should be entered by the user.


Note: The dot after the test command is important.

[root@server ~]# telnet localhost smtp


Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 server.ostechnix.com ESMTP Postfix
ehlo localhost
250-server.ostechnix.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<[email protected]>
250 2.1.0 Ok
rcpt to:<[email protected]>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test
.
250 2.0.0 Ok: queued as 117113FF18
CentOS 7 –install & configure Postfix – Dovecot |

quit
221 2.0.0 Bye
Connection closed by foreign host.

Check Mail
Navigate to the user mail directory and check for the new mail.

[root@server ~]# cd /home/user1/Maildir/new/


[root@server new]# ls
1360236956.Vfd00I35afM181256.server.ostechnix.com
[root@server new]# cat 1360236956.Vfd00I35afM181256.esprit.com
Return-Path: <[email protected]>
X-Original-To: user1
Delivered-To: [email protected]
Received: from localhost (localhost [IPv6:::1])

4
by esprit.com (Postfix) with ESMTP id 117113FF18
for <user1>; Thu, 7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <[email protected]>
Date: Thu, 7 Feb 2013 17:05:32 +0530 (IST)
From: [email protected]
To: undisclosed-recipients:;
test
Postfix working now.
Step 7 : Install Dovecot

Dovecot is used to allow users to access their email by either imap or pop protocols.
[root@server ~]# yum -y install dovecot

Step 8 : Configure Dovecot

Open the dovecot config file /etc/dovecot/dovecot.conf. Find and uncomment the line as
shown below.

[root@server ~]# nano /etc/dovecot/dovecot.conf


#line 24 uncomment
protocols = imap pop3 lmtp
#line 30:uncomment and change(if not use IPv6 )
listen = *
Open the file /etc/dovecot/conf.d/10-mail.conf and uncomment the line as shown below.
[root@server ~]# nano /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir ##line no 24 - uncomment
Open the /etc/dovecot/conf.d/10-auth.conf and edit as shown below.
CentOS 7 –install & configure Postfix – Dovecot |

[root@server ~]# nano /etc/dovecot/conf.d/10-auth.conf


disable_plaintext_auth = no ##line no 10 - uncomment and chang to no.
auth_mechanisms = plain login ##line no 100 - add the text "login"
Open the /etc/dovecot/conf.d/10-master.conf and edit as shown below.

# line 96-98: uncomment and


add like follows
# Postfix smtp-auth
unix_listener
/var/spool/postfix/priate/
{
mode = 0666
user = postfix
group = postfix
}

Restart the dovecot service.


[root@server ~]# systemctl restart dovecot

[root@server ~]# systemctl enable dovecot


Again, looking at each option:

protocols: specifies the protocols available to users to access their email. Dovecot supports
imap(s) and pop3(s), and any or all may be used.

mail_location: specifies the format and location of each users mailbox. Here we see we are
using maildir format and each user has their mailbox located at ~/Maildir. Examples for
mbox format are provided in the configuration file.

Step 9 : Test Dovecot using the command telnet

The commands shown in bold should be entered by the user.


[root@server ~]# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user user1
+OK
pass user1
+OK Logged in.
list
+OK 1 messages:
1 428
.
retr 1
+OK 428 octets
Return-Path: <[email protected]>
X-Original-To: user1
Delivered-To: [email protected]
Received: from localhost (localhost [IPv6:::1])
by esprit.com (Postfix) with ESMTP id 117113FF18
for <user1>; Thu, 7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <[email protected]>
CentOS 7 –install & configure Postfix – Dovecot |

Date: Thu, 7 Feb 2013 17:05:32 +0530 (IST)


From: [email protected]
To: undisclosed-recipients:;
test
.
quit
+OK Logging out.
Connection closed by foreign host.
[root@server ~]#

Required tests:
After testing postfix and dovecot with user1 now try to send a Mail from user 1 to user 2 and
check if user2 receives the mail.
Mail Clients’Setting

6
Configure for your Mail Client on your PC. This example shows with Mozilla Thunderbird.
[1] Run Thunderbird and Click [Create a new account] - [EMAIL].

[2] Click [Skip this and use my existing email].


[3] Input any name which is displayed as email-Sender and also input email address and password, and
then Click [Continue] button

[4] Click [Manual config] button.


[5] Confirm selection and also confirm [Authentication] fields are selected [Normal password] like follows,
then Click [Done] to finish. After finishing it, Warning message is shown because connection to servers are not
encrypted, Accept it or Cancel this setting and Configure SSL/TLS, too on the next section.

[6] If email account setup normally, it's possible to send or receive emails like follows.

You might also like