If you’re looking for an alternative to traditional mail servers like Gmail and want to transform your Ubuntu machine into a mail server, you’ve come to the right place.
This guide will walk you through the process of setting up a Postfix mail server on your Ubuntu and then use Thunderbird to test it out. The instructions provided here are primarily for Ubuntu 22.04, but they can also be applied to Debian or Mint.
SMTP, or Simple Mail Transfer Protocol, is a technical protocol used by mail servers to send, receive, and relay outgoing emails between senders and receivers. This protocol facilitates the exchange of data between computers and servers, irrespective of the hardware or software they use. Just as standardizing envelope addressing aids the postal service, standardizing email transmission through SMTP enables efficient email delivery.
SMTP is a mail delivery protocol, not a mail retrieval one. It’s akin to the postal service delivering a letter to a mailbox; the recipient still needs to collect it. Similarly, SMTP delivers emails to the mail servers of email providers. However, different protocols are used to retrieve these emails from the mail servers for recipients to read.
Each networking protocol has a specific procedure for data exchange. SMTP outlines a method for transmitting data between an email client and an Ubuntu mail server. An email client is a computer or web application that a user employs to access and send emails. Users interact indirectly with mail servers, which are specialized computers designed to send, receive, and forward emails.
Read: How to Configure Sendmail on Ubuntu 22.04
When communicating via email, it’s crucial that your emails are sent securely and promptly to your recipient. Without an SMTP server, your email won’t reach its intended destination. When you click Send, your email transforms into a code string that is then sent to the SMTP server. This server interprets the code to deliver the message. Without processing by the SMTP server, the message wouldn’t be translated. The SMTP server also verifies that the email originates from an active account, protecting your mailbox from spam.
The SMTP protocol ensures that if an email fails to deliver, it will bounce back to the sender with information about why it was rejected—either due to an invalid sender email address or rejection by the recipient’s email server. Whether you’re a small, medium, or large enterprise, having your own email server is essential. Join us as we walk through all the necessary steps to install and configure an SMTP Server with Postfix on Ubuntu.
A Fully Qualified Domain Name (FQDN) is the complete domain name for a specific computer or host connected to the internet. It consists of two parts: the hostname and the domain name. For example, an FQDN could be mail.company.com. Here’s how to set up an FQDN in Ubuntu:
For instance, if you want to add a hostname called net2host with an IP address 180.0.2.10, you would add the following line in the /etc/hosts file:
180.0.2.10 net2host.
6. Save the file and verify the domain name with the hostname –f command.
Read: How to send one-liner emails from Linux/Ubuntu terminal
Before proceeding, ensure all APT repositories on your Ubuntu PC are up-to-date by running these commands in the terminal:
sudo apt update
sudo apt upgrade
Read: How to install and uninstall applications in Ubuntu? A Beginner’s guide
Postfix mail server handles email transmission and reception. To install it, enter sudo apt-get install postfix in the terminal.
This will bring up the window below:
During the installation process, you will encounter a series of interactive prompts. In this tutorial, we recommend using the provided information to respond to these prompts:
To summarize:
In case you need to revisit and modify these configurations, you can achieve this by entering the following command:
sudo dpkg-reconfigure postfix
You’ll find that the prompts already contain your earlier provided answers.
Read: How to install Apache web server on Ubuntu?
To check is your Postfix server is running or not, run the command below :
sudo systemctl status postfix
As shown above, Postfix is currently operational and functioning on our Ubuntu 22.04 system.
To prevent potential firewall restrictions on Postfix, utilize the following commands to enable Postfix functionality:
sudo ufw allow ‘Postfix’
We will now test how to use Postfix to manage Emails locally. We run the command below to change the configuration to Local :
sudo dpkg-reconfigure postfix
Then we select the option below:
Now we make sure Postfix is active by running :
sudo systemctl status postfix
Next run the command below in a net terminal session:
telnet localhost 25
Where 25 is the post for SMTP.
Now we write the command:
ehlo localhost
Right after the prompt above .
Now we write :
mailfrom: net2test@net2.com
As shown below:
We end up getting the output below :
Next we we will mention the recipient :
rcpt to: net2@localhost
Where net2 is the name of current user.
We then write the word: DATA
Then we mention the subject of the Email:
subject: net2test
And then the body:
Hi there this is net2
Finally, you should write a dot “.” at the end to quit and not the word quit or :q like we did below.
Read: How to set up a firewall on Ubuntu 22.04
Now let us check the whereabouts of this message. In the file explorer, go to the folder:
below: computer/vr/mail
And open up the file shown above and scroll down to the very end:
We can see the text that we have sent earlier.
Dovecot, a Mail Delivery Agent (MDA) that functions as a POP and IMAP server, is designed with a strong emphasis on security. Its role is to manage local mail directories, allowing users to access and retrieve their mail. It is compatible with the main mailbox formats, namely mbox and Maildir. Dovecot is responsible for receiving incoming mail from Postfix for delivery. However, before this delivery can take place, Dovecot must authenticate the virtual users connected over SMTP.
To install Dovecot MDA, use the command below:
sudo apt-get install dovecot-imapd dovecot-pop3d
Now you should restart Dovecot by invoking the command below:
sudo service dovecot restart
Read: Best Email clients of 2023
Let us now invoke the command :
telnet localhost 143
Next we write :
a login “net2” “yourpassword”
As shown below :
Then we write:
b select inbox
Next we write :
c list “” *
Finally, to log out, write the command:
e logout
Now we will go ahead and run Thunderbird application on Ubuntu 22.04. Follow the steps below in order to be able to send and receive Emails on your local computer.
On your terminal, write the command below :
telnet localhost 143
Next write :
b select inbox
Then type in :
c list “” *
And make sure it is double quotes.
To log out, write :
e logout
Now, on your Ubuntu dashboard, click on Thunderbird icon . This will bring up the window below :
Enter your own credentials as shown above and below :
Finally, your account should be created and you will be able to start sending and receiving Emails on your local host.
Click ok and confirm the next dialog boxes.
As you can see, this is the Email that we created earlier.
In this comprehensive guide, we have covered the process of setting up an SMTP server on Ubuntu 22.04, enabling you to establish your own Ubuntu email server instead of relying on conventional services like Gmail. Understanding the fundamentals of SMTP servers and their role in email communication is vital to ensure secure and efficient email delivery. We’ve explored the significance of having your SMTP server, emphasizing its ability to validate email origins and handle delivery failures effectively.
We’ve also walked you through key steps, such as configuring a Fully Qualified Domain Name (FQDN), updating repositories, and installing the Postfix mail server.
Additionally, we’ve discussed how to verify the status of your Postfix server and configure your firewall to avoid any potential restrictions.
Furthermore, we’ve demonstrated how to test Postfix functionality locally, allowing you to manage emails efficiently.
We’ve also introduced Dovecot, a secure Mail Delivery Agent (MDA) responsible for managing local mail directories and enabling users to access their mail. We provided instructions for its installation and demonstrated its functionality.
Lastly, we’ve guided you through using Mozilla Thunderbird, a popular email client, to send and receive emails. By following these steps, you can create your email account and enjoy efficient email communication on your local machine.
With this guide, you are well-equipped to establish and manage your SMTP server, enhancing your control and security over email communication.
The post How to set up an SMTP server on Ubuntu 22.04 appeared first on net2.
Deploying FreePBX and Asterisk on a single Ubuntu virtual machine in a public cloud is…
Canonical and MediaTek enhance reliability, accelerate market entry and reduce Total Cost of Ownership (TCO)…
As Ubuntu 20.04 LTS (Focal Fossa) standard support ends on May 31, 2025, Azure users…
Welcome to the Ubuntu Weekly Newsletter, Issue 881 for the week of February 23 –…
Welcome back, data scientists! In my previous post, we explored how easy it is to…
In this article, we will see how to install vLLM on Linux using 4 easy…