Skip to content
Logo SR
  • Home
  • Português
  • English
  • About
Logo SR
  • Home
  • Português
  • English
  • About

How to Set Up a Postfix and Dovecot Email Server on Linux: A Step-by-Step Guide

Network, Servers

This is a tutorial that will present a basic configuration of an email server using Postfix and Dovecot. The idea here is to configure an email server to enable sending and receiving emails among internal clients.

Português

Because it is an asynchronous communication, email is ideal for communications in which a user does not need to wait for the recipient user to be online.

Thus, when we send an email, the recipient will only have access to it at the moment they connect to their email inbox.

Table Of Contents
  1. Installing and configuring Postfix
    • Basic Postfix configuration
  2. Installing and configuring Dovecot
  3. Creating users on the Postfix server
  4. Installing and configuring thunderbird
    • Configuring the hosts file on the client machine
    • Installing thunderbird
    • Configuring the user email account in thunderbird
    • Setting up a second email account
    • Sending an email from one user to another in Thunderbird.

Installing and configuring Postfix

We will use Postfix because it is one of the main email sending servers, with widespread global distribution.

The figure below shows that we will start our tutorial by configuring the email server.

To install Postfix, we will use the command below.

sudo apt install postfix

Then confirm the installation.

Next, we will choose the type of configuration used in our Postfix. For this tutorial, we will use the “Internet Site” mode. This model is interesting because it allows future integration with external domains.

Now, we will give a name to the email server. In this case, we can use a local domain or a domain that we have on the Internet.

In this case, we are doing a local configuration and will use a fictitious domain “labredes.teste“. You can use the domain that is most suitable for your case.

After clicking “Ok“, we will see the server finishing the configuration.

Once Postfix is installed, let’s check if the server is listening on TCP port 25, which is the SMTP port.

To check if the Postfix server is listening on port 25, we will use the command below.

ss -nlt

Basic Postfix configuration

To configure Postfix, we will access the “main.cf” file and make changes. To edit the “main.cf” file, we will use the nano editor and can use the command below.

sudo nano /etc/postfix/main.cf

Next, we will comment on some parts of the “main.cf” file configuration.

  • # = Comments.
  • 1 = Displays “$myhostname” provided in the file itself as well as “$mail_name“. This presentation banner can be useful when you want to provide some information to the user, for example: “This is server 1“.
  • 2 = Allows new email notification for users and is usually disabled because it can affect server performance.
  • 3 = If sent locally, it adds the string “.$Mydomain” to addresses that do not have “.domain” information. If sent remotely, it adds the sequence “.$Remote_header_rewrite_domain”.
  • 4 = Location where Postfix README files describe the building, configuration, or operation of a specific Postfix feature.
  • 5 = Allows compatibility with previous versions. Ideal after upgrading to a newer version of Postfix.

The figure above shows the configurations used in message encryption/security.

  • 1 = Access restrictions for email relay control. Postfix SMTP applies it in the context of the “RCPT TO” command.
  • 2 = The hostname of this email system. The default is to use the fully qualified domain name (FQDN) of “gethostname()” or use the non-FQDN result of “gethostname()” and append “. $ Mydomain”.
    FQDN = Fully Qualified Domain Name.
  • 3 = Information for alias databases for local server delivery.
  • 4 = Defines the domain that will be used as origin (or “my origin“) for emails sent by the mail server. This configuration is important because Postfix uses this value to determine which domain will be used in the “From” field of emails sent locally or to define the origin domain of emails that are delivered to other servers.
  • 5 = The list of domains delivered via the “$local_transport” message delivery transport.
    In the Postfix local delivery agent, it looks for recipients in /etc/passwd and /etc/aliases.
    Only using the default “mydestination” specifies names for the local machine only.
    On a mail domain gateway, you must also include “$mydomain”. Note: Here I added my domain “labredes.teste”.
  • 6 = The next-hop destination for non-local mail. It replaces non-local domains in recipient addresses.
  • 7 = A list of network addresses or network/mask patterns separated by commas and/or whitespace
    “trusted” SMTP clients are allowed to relay messages through Postfix.
  • 8 = The maximum size of individual mailboxes or local “maildir” file, zero means unlimited.
  • 9 = The set of characters that can separate a username from its extension (example: usuario + xyz).
  • 10 = The interface on which the Postfix server will listen. “all” means all the machine’s interfaces.
  • 11 = When set to all, Postfix will use both IPv4 and IPv6 to communicate.

Important: Add these two lines at the end of the configuration file.

home_mailbox = Maildir/
resolve_numeric_domain = yes
  • 1 = Routing to the mail directory of the users registered on the Postfix server machine.
  • 2 = Allows address resolution using IP.

To save the change in the nano editor, we can use “CTRL + x” and then type “y”.

Then, restart the Postfix server with the command below.

sudo service postfix restart

You can also check the status of the postfix server with the command below.

sudo service postfix status

Installing and configuring Dovecot

We will use Dovecot to be able to receive emails using the IMAP protocol. However, it is worth remembering that Dovecot can also use POP3.

First, let’s install Dovecot with the command below.

sudo apt install dovecot-core dovecot-imapd

After that, we will edit the file “dovecot.conf” using nano.

sudo nano /etc/dovecot/dovecot.conf

As in the figure below, we will uncomment the line “listen = *, ::“.

To save the change in the nano editor, we can use “CTRL + x” and then type “y”.

Now, we will restart the Dovecot server with the command below.

sudo service dovecot restart

Next, we will check the status of Dovecot with the command below.

sudo service postfix status

Now, let’s configure the “10-mail.conf” file, and for that, we will edit the file with the command below.

sudo nano /etc/dovecot/conf.d/10-mail.conf

Inside the file, we will comment out the line “mail_location = mbox:~/mail:INBOX=/var/mail/%u” and uncomment the line “mail_location = maildir:~/Maildir“.

To save the change in the nano editor, we can use “CTRL + x” and then type “y”.

Now, we will configure the “10-master.conf” file, and for that, we will edit the file with the command below.

sudo nano /etc/dovecot/conf.d/10-master.conf

Inside the file, we will uncomment the lines:
“unix_listener /var/spool/postfix/private/auth {”
and
“mode = 0666“.

And we will add the lines:
“user = postfix“
“group = postfix“

And uncomment “}“.

To save the change in the nano editor, we can use “CTRL + x” and then type “y“.

Now, we will restart Dovecot so that the changes take effect. To restart the server, we will use the command below.

sudo service dovecot restart

Creating users on the Postfix server

Remember that in the Postfix configuration line we used: “home_mailbox = Maildir/”. Therefore, Postfix will look for users created within the machine running the Postfix service.

Thus, we need to create users within the Postfix machine.

In this tutorial, we will create 2 users: “alice” and “maria“.

To create the user “alice” we will use the command below.

sudo adduser alice

Now let’s create the user “maria” with the command below.

sudo adduser maria

We can use the command below to see the users we created.

ls /home/

Installing and configuring thunderbird

Now we will go to a client machine and install the email reading application “thunderbird“. You can choose another email reading application that you prefer.

The figure below shows that now we will configure the client that will access the email server.

But before anything else, we will make a configuration in the hosts file of the client machine.

Configuring the hosts file on the client machine

You might be wondering why we are configuring the hosts file on the client, right?

It’s good that you asked. The reason we are configuring the hosts file is because “thunderbird” does not accept IP addresses as domain names. Therefore, we will create some local aliases in the client machine’s hosts file.

To configure the client machine’s hosts file, we will use the command below.

sudo nano /etc/hosts

Then, we will add a line at the end of the file containing the IP of the email server and the name we will assign to the email server.

  • 1 = The IP of our email server, where Postfix is installed.
  • 2 = The name we gave our email server.

Installing thunderbird

To install “thunderbird” we will use the command below.

sudo apt install thunderbird

After that, you can type the command below or run “thunderbird” in the programs area of your graphical interface.

thunderbird

Configuring the user email account in thunderbird

Once “thunderbird” is started, we will configure the account of the user that we have registered on the email server. In this case, we will enter information for the user “alice“.

For that, we will enter the name “alice” and then we will enter the email. For the email, we will use the user’s name and the name we mapped in our client’s “hosts” file.

If you are using a DNS with the email server mapped, you can use your DNS name followed by your domain.

After entering the information, we will click “Continue” and then “Done“.

Next, we will see a security alert and will click “Confirm Security Exception” to validate our configuration.

After that, we will see the screen below saying that the email account for the user has been set up. Then, we will click “Finish“.

Now, we will click “New Message” and write a test email.

In this case, we will create a test email from user Alice to herself. Below I explain the fields we filled in this configuration.

  • 1 = Here we will enter the recipient’s email. In this case, since it’s just the first test, it will be for Alice herself.
  • 2 = Next, we will enter the subject of the email.
  • 3 = Then, we will enter text in the email.
  • 4 = We will click “Send” to send the email.

Next, we will see a second security alert and will click “Confirm Security Exception” to validate our configuration.

After that, a message will appear saying that sending the email failed, and we will click “OK“. This message appears because the certificate we are using for our email server is self-signed.

For this scenario, we can click “OK” and then we will click “Send“.

Now, we can see that a message has arrived in the “Inbox” of the user. So, we will click on “Inbox“.

After clicking on “Inbox“, we will see that the message we sent is present.

Setting up a second email account

Now, we will set up a second email account so that we can test sending from one user to another.

Note: There is no need to have two email user accounts registered on the same machine. We are doing this only so that we do not have to turn on a second machine with “thunderbird“.

To do this, let’s click on the symbol in the figure below indicated by the red arrow.

Next, let’s click on “Account Settings” as shown in the figure below.

After that, let’s follow the steps shown in the figure below.

  • 1 = First, let’s click on “Account Actions“.
  • 2 = Click on “Add Mail Account“.

After that, let’s start setting up the second email user account. In this case, we are configuring the account for the user “maria“.

Therefore, we will make a similar configuration to what we did for the user “alice“, differentiating by username and password.

After setting up the new user’s account, let’s click on “Continue” and then on “Done“.

Now, we can see that the second email user account has been successfully created in “Thunderbird” and we can click on “Finish“.

Sending an email from one user to another in Thunderbird.

Now that we have two user accounts set up in “Thunderbird,” we can send an email from one user to another and see if the email has arrived at the other user’s inbox.

To perform the test, we will click “New Message” and start writing the message.

Notice, in the figure below, that we are sending the email with the origin being user “alice” and the recipient being user “maria“. After entering the information, we will click “Send“.

We can see, in the figure below, that a message has arrived in the “Inbox” of the user “maria“.

By clicking on “Inbox” for user Maria, we will see the message that was sent by Alice.

See more:

Build Your Own DNS Server: A Step-by-Step Guide using BIND9

Tutorial for SSH Public Key Authentication

How to use Ngrok

Install ubuntu 24 on virtualbox

How to X11 Forwarding using SSH

Squid Proxy for Linux Installation and Configuration

Juliana Mascarenhas

Data Scientist and Master in Computer Modeling by LNCC.
Computer Engineer

Linkedin

https://www.postfix.org

dovecot.org

← Previous Post
Next Post →

Related Posts

OpenWRT in VirtualBox

Network, OpenWRT_en, Raspberry PI en, VirtualBox_en, virtualization

pfBlockerNG Customize Blocklist

Network, pfBlockerNG_en, PfSense_en

Android with VirtualBox

Network, VirtualBox_en, virtualization

Virtualizing the Raspberry Pi – Raspbian

Network, Raspberry PI en, VirtualBox_en, virtualization

Squid Proxy for Linux Installation and Configuration

Network, Proxy_en, Servers

PfBlockerNG: Exception List for Clients

Network, pfBlockerNG_en, PfSense_en
  • Português
  • English
  • Blockchain (3)
  • Data (9)
    • Data Science_en (3)
    • Database (6)
  • Network (66)
    • Cloud_en (2)
    • OpenWRT_en (3)
    • PacketTracer_en (4)
    • Protocol (13)
    • Proxy_en (6)
    • Servers (9)
  • PfSense_en (9)
    • pfBlockerNG_en (3)
  • programming (18)
    • Java_en (3)
    • Python_eng (13)
  • Raspberry PI en (7)
  • security (19)
    • Suricata_en (3)
  • Sem categoria (1)
  • virtualization (19)
    • Docker_en (6)
    • VirtualBox_en (13)
  • VPN_en (8)
  • Zabbix_en (5)
  • Português

Latest Articles

  • Packet Tracer network with one router
  • How to Use Snap Behind a Proxy on Linux (Step-by-Step Guide) 
  • How to Create a Network with a Switch in Packet Tracer – Step-by-Step Guide for Beginners
  • Why use Kali Linux inside VirtualBox?
  • How to install pfBlocker on pfSense: step by step guide
  • Packet Tracer for Dummies: Setting Up Your First Network with 2 PCs (Quick Start Guide)
  • Learn how to use the curl command: tutorial with practical examples
  • How to Install Kali Linux on VirtualBox: Step-by-Step Guide for Beginners
  • Python Package Managers: Pip and Conda – A Complete Beginner’s Guide
  • What is CGNAT ?
  • Tutorial: How to use WHOIS and RDAP
  • How to Set Up a Postfix and Dovecot Email Server on Linux: A Step-by-Step Guide
  • Tutorial how to Install and configure VNC on Ubuntu
  • Build Your Own DNS Server: A Step-by-Step Guide using BIND9
  • Tutorial for SSH Public Key Authentication
  • Socket UDP Python Chat
  • Socket TCP Python make a chat
  • apt get behind proxy
  • Best IDE for Python?
  • Python get metadata from images and pdfs
  • Português
  • English
  • Cookie Policy / Política de Cookies
  • Privacy Policy
  • About
We use cookies on our website remembering your preferences and visits. By clicking “Accept All”, you consent to the use of ALL the cookies. Visit " Settings" to provide a controlled consent./ Usamos cookies no site lembrando suas preferências e visitas. Clicando em “Aceitar todos”, você concorda com o uso de TODOS os cookies. visite "Configurações cookies" para um consentimento controlado.
Settings/ConfiguraçõesAccept All / Aceitar tudo
Manage consent / Gerenciar consentimento

Privacy Overview / Visão geral da privacidade

This website, uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience. **/** Este site usa cookies para melhorar a sua experiência enquanto navega pelo site. Destes, os cookies que são categorizados como necessários são armazenados no seu navegador, pois são essenciais para o funcionamento das funcionalidades básicas do site. Também usamos cookies de terceiros que nos ajudam a analisar e entender como você usa este site. Esses cookies serão armazenados em seu navegador apenas com o seu consentimento. Você também tem a opção de cancelar esses cookies. Porém, a desativação de alguns desses cookies pode afetar sua experiência de navegação.
Necessary_en
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-advertisement1 yearSet by the GDPR Cookie Consent plugin, this cookie is used to record the user consent for the cookies in the "Advertisement" category
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". O cookie é definido pelo consentimento do cookie GDPR para registrar o consentimento do usuário para os cookies na categoria "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". Este cookie é definido pelo plug-in GDPR Cookie Consent. Os cookies são usados para armazenar o consentimento do usuário para os cookies na categoria "Necessary",
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other".
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. O cookie é definido pelo plug-in GDPR Cookie Consent e é usado para armazenar se o usuário consentiu ou não com o uso de cookies. Ele não armazena nenhum dado pessoal.
Functional_en
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
CookieDurationDescription
pll_language1 yearThe pll _language cookie is used by Polylang to remember the language selected by the user when returning to the website, and also to get the language information when not available in another way.
Performance_en
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
CookieDurationDescription
_tccl_visit30 minutesThis cookie is set by the web hosting provider GoDaddy. This is a persistent cookie used for monitoring the website usage performance.
_tccl_visitor1 yearThis cookie is set by the web hosting provider GoDaddy. This is a persistent cookie used for monitoring the website usage performance.
Analytics_en
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
CookieDurationDescription
__gads1 year 24 daysThe __gads cookie, set by Google, is stored under DoubleClick domain and tracks the number of times users see an advert, measures the success of the campaign and calculates its revenue. This cookie can only be read from the domain they are set on and will not track any data while browsing through other sites.
_ga2 yearsThe _ga cookie, installed by Google Analytics, calculates visitor, session and campaign data and also keeps track of site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognize unique visitors.
_gat_gtag_UA_199766752_11 minuteSet by Google to distinguish users.
_gid1 dayInstalled by Google Analytics, _gid cookie stores information on how visitors use a website, while also creating an analytics report of the website's performance. Some of the data that are collected include the number of visitors, their source, and the pages they visit anonymously.
Advertisement_en
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
CookieDurationDescription
test_cookie15 minutesThe test_cookie is set by doubleclick.net and is used to determine if the user's browser supports cookies.
Others_en
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
CookieDurationDescription
FCCDCF12 hoursNo description available.
GoogleAdServingTestsessionNo description
SAVE & ACCEPT
Powered by CookieYes Logo