LAB 3 Messagerie

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Ubuntu 22.

04 –install & configure


Postfix–Dovecot

Services et Administration des Réseaux

Esprit 2023/2024

1
Ubuntu 22.04 –install & configure
Postfix – Dovecot
Services et Administration des Réseaux

Introduction:

Setting up a robust and reliable email infrastructure is a fundamental requirement for modern
communication. In this lab, we will delve into the installation and configuration of an email server on
Ubuntu 22.04, with the domain name montpdomain.lan

Our email server will utilize two critical components: the Mail Transfer Agent (MTA) and the Mail
Delivery Agent (MDA). These components play distinct yet complementary roles in ensuring the
smooth flow of electronic mail.

MTA (Mail Transfer Agent): Think of the MTA as the postal service of the digital world. It is responsible
for routing and transferring emails from the sender's client to the recipient's server. Our choice for this
role is Postfix, a highly efficient and secure MTA that has become a standard in the industry.

MDA (Mail Delivery Agent): Once emails arrive at the recipient's server, they need to be sorted and
placed into the correct mailbox. This is where the MDA comes into play. We will use Dovecot as our
MDA, which provides robust support for the Internet Message Access Protocol (IMAP) and Post Office
Protocol (POP3), allowing users to access their emails seamlessly.

By following the steps in this lab manual, you will develop a comprehensive understanding of how to
configure these components, ultimately constructing a functional email server tailored to your
communication needs. Let's begin the process of setting up your email infrastructure with Postfix and
Dovecot on Ubuntu 22.04!

Objectifs:
✓ Adduseraccounts(user1 and user2).
✓ Installing the MTA and MDA services.
✓ Configuring Postfix and Dovecot software module.
✓ Testing

Step 1 : Creating the users


1
Create the first user:

# sudo useradd -m user1


# sudo passwd user1
Create the second user:
# sudo useradd -m user2
# sudo passwd user2
2
Step 2 : Install Postfix server

To update the list of available packages, run the following command

# sudo apt-get update

# sudo apt-get install postfix


This installation process will open a series of interactive prompts ,these are the settings used :
• General type of mail configuration?: Internet Site
• System mail name: montpdomain.lan (not mail.montpdomain.lan)
• Root and postmaster mail recipient: The username of your primary Linux account
• Other destinations to accept mail for: $myhostname, localhost.$mydomain, localhost, $mydomain
• Force synchronous updates on mail queue?: No
• Local networks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128, 10.0.2.0/24
• Mailbox size limit: 0
• Local address extension character: +
• Internet protocols to use: all

Step 3 : Configuring Postfix

Open the postfix config file /etc/postfix/main.cf. Find the below lines and edit them as shown
below.
To set the mailbox format, you can edit the configuration file directly, the configuration parameters
will be stored in /etc/postfix/main.cf file.

#sudo gedit /etc/postfix/main.cf

Find the below lines and edit them as shown below.

# Specify the hostname for this mail server.


myhostname = mail.montpdomain.lan
#Define the origin of locally-posted mail In this case, this file should contain
#'montpdomain.lan'.
myorigin = /etc/mailname
#List the destination domains for which this mail server will receive mail
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# Leave the relay host empty, indicating this server performs local mail delivery.
relayhost =
# Specify a list of trusted networks that can relay mail through this server.
# This includes localhost and a local network range (10.0.2.0/24).
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128, 10.0.2.0/24
# Set the mailbox size limit to 0, indicating unlimited mailbox size.
mailbox_size_limit = 0
# Define the recipient delimiter used in recipient addresses.
# It's set to '+' here but can be changed if needed.
recipient_delimiter = +
# Specify that the server should listen on all network interfaces.
inet_interfaces = all
# Allow all network protocols.
inet_protocols = all
# Define the mailbox format and location for user mailboxes.
# Here, it's set to use the Maildir format. Add this line 3
home_mailbox = Maildir/
Step 4 : Creating a System Alias
You can create a system alias for each user you create. The system alias will redirect all
emails intended for that user to a complete email address with the "montpdomain.lan"
domain.
#sudo gedit /etc/aliases
Add a line like this to the end of the aliases file:

user1: user1@montpdomain.lan
user2: user2@montpdomain.lan

Update the Alias Database


#sudo newaliases

Step 5 : 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:

#sudo apt install ufw

#sudo ufw allow 25/tcp

#sudo ufw allow 110/tcp

#sudo ufw allow 143/tcp

To apply firewall rules (reload UFW rules):


# sudo ufw reload

To enable and check UFW rules:


#sudo ufw enable

# sudo ufw status

4
Step 6 : Start the services
After finishing the configuration we should start the service and keep it on
#sudo systemctl restart postfix

Step 7 : 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@machine-serveur:/home# telnet localhost smtp


Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.montpdomain.lan ESMTP Postfix (Ubuntu)
ehlo localhost
250-mail.montpdomain.lan
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
mail from:user1@montpdomain.lan
250 2.1.0 Ok
rcpt to:user2@montpdomain.lan
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test
.
250 2.0.0 Ok: queued as 3642480116
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@machine-serveur:/home/user2/Maildir/new# cd /home/user2/Maildir/new
root@machine-serveur:/home/user2/Maildir/new# ls
1694966621.V803Ie0ac5M630309.machine-serveur
root@machine-serveur:/home/user2/Maildir/new# cat
1694966621.V803Ie0ac5M630309.machine-serveur
Return-Path: <user1@montpdomain.lan>
X- Original-To: user2@montpdomain.lan
Delivered-To: user2@montpdomain.lan
Received: from localhost (localhost [127.0.0.1])
by mail.montpdomain.lan (Postfix) with ESMTP id 3642480116
for <user2@montpdomain.lan >; Sun, 17 Sep 2023 17:03:15 +0100 (WAT)
Message-Id: <20230917160332.3642480116@mail.montpdomain.lan >
Date: Sun, 17 Sep 2023 17:03:15 +0100 (WAT)
From: user1@montpdomain.lan

test
5
Postfix working now.
Step 8 : Install Dovecot

Dovecot is used to allow users to access their email by either imap or pop protocols.
#sudo apt-get install postfix dovecot-imapd dovecot-pop3d
#

Step 9 : Configure Dovecot


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

#gedit /etc/dovecot/dovecot.conf

#line 30:uncomment
listen = * , ::
#line 24:uncomment
!include_try /usr/share/dovecot/protocols.d/*.protocol

Open the file /etc/dovecot/conf.d/10-mail.conf and uncomment the line as shown below.

# gedit /etc/dovecot/conf.d/10-mail.conf

mail_location = maildir:~/Maildir ##line no 24 –uncomment

"Make sure to have only one mail_location directive uncommented in the configuration."

Open the /etc/dovecot/conf.d/10-auth.conf and edit as shown below.

# gedit /etc/dovecot/conf.d/10-auth.conf

disable_plaintext_auth = no ##line no 10 - uncomment and change 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.

# gedit /etc/dovecot/conf.d/10-master.conf

# line 107-109: uncomment and add like follows


# Postfix smtp-auth

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

mode = 0666
user = postfix
group = postfix
6
}
Restart the dovecot service.
# sudo systemctl restart dovecot

# sudo systemctl enable dovecot

Step 10 : Test Dovecot using the command telnet

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


[root@machine-serveur]# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user user2
+OK
pass user2
+OK Logged in.
list
+OK 1 messages:
1 428
.
retr 1
+OK 428 octets
Return-Path: <user1@ostechnix.com>
X-Original-To: user1
Delivered-To: user1@ostechnix.com
Received: from localhost (localhost [IPv6:::1])
by montpdomain.lan (Postfix) with ESMTP id
117113FF18
for <user1>; Thu, 7 Feb 2013 17:05:32 +0530 (IST)
Message-Id:
<20130207113547.117113FF18@montpdomain.lan> Date:
Thu, 7 Feb 2013 17:05:32 +0530 (IST)
From: user1@montpdomain.lan
To: undisclosed-recipients:;
test
.
quit
+OK Logging out.
Connection closed by foreign host.

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

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].


7
[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.

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

safa.hachani@esprit.tn

10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy