The purpose of this post is to enable you to set up your own email server. For this purpose, we chose Postfix as a mail server. Postfix is a free and open-source mail transfer agent that routes and delivers electronic mail.
In this post, we will explain how to install and configure the Postfix mail server on the Ubuntu 18.4 server.
For installing a Postfix server, your user should have sudo privileges (admin rights for installing Postfix). If you want to receive emails from the internet, you should have DNS Records for Your Mail Server. You must ensure Port 25 is open so Postfix can receive emails from other SMTP servers.
Before starting configuring the Postfix server, you need to make sure that proper entries in /etc/hosts as most of programs will not accept an email using just @localhost as a domain.
Your host file will look something like this.
Installing Postfix on the Ubuntu server is quite a simple task, but after installing Postfix, you need to make sure that you configure Postfix server properly.
Install the Postfix package if it is not installed already.
Enabling this, you can use any email address ending with "@localhost" or "@localhost.com".
If it does not exist, create file /etc/postfix/virtual:
Add the following 2 lines content, replacing with your Unix user account:
To Change the configuration of the Postfix server we need to read this file:
And check if this line is enabled in main.cf, or add it if it does not exist:
Save and close this file and activate these changes by running the below commands:
Open Postfix configuration file
Add below lines after inet_protocoles and save main.cf
Reload postfix and restart it:
Your /etc/postfix/main.cf will look like this:
Let Postfix know about the domains that it should consider local:
Let Postfix know about the IPs it should consider as part of the LAN: We’ll assume 192.168.1.0/24 is your local LAN. You can safely skip this step if you don’t have other machines in the same local network.
Remember to reload the Postfix configuration and restart it.
Checking Postfix server status.
Starting Postfix server.
Stopping Postfix server.
For testing the Postfix server, first, we will install mailutils for sending mail to the local server.
Execute the below command to send mail to the local mail server
and check mail /Maildir/new. If you receive any file in this folder, then your postfix server is configured properly, and your mail server setup is complete for receiving emails from the local network.
Postfix requires the server’s hostname to identify itself when communicating with other MTAs. The hostname can have a Single word or a Fully Qualified Domain Name(FQDN). FQDN is usually used for internet-facing servers. You should set up DNS records for your mail server in your DNS hosting service. In this, you have to setup MX record and A record.
MX reco*rd: An MX record tells other MTAs that your mail server mail. syscotest.com is responsible for email delivery for your domain name.
A record: An A record maps an FQDN to an IP address.
Run below command in terminal to install Postfix server.
The installation process will ask you to select mail configuration. You need to select Internet Site for this.
No configuration means the installation process will not configure any parameters.
Internet Site means using Postfix for sending emails to other MTAs and receiving email from other MTAs.
Internet with smarthost means using Postfix to receive emails from other MTAs but using another smart host to relay emails to the recipient.
Satellite system means using a smart host for sending and receiving email.
Local only means emails are transmitted only between local user accounts. (For Goal 1, select this option)
In step, it will ask you to enter the domain name for the system mail name. In our case, we have entered “syscotest.com” as the system mail server.
Once installed, check Postfix configuration file “/etc/postfix/main.cf” by opening it in your favorite editor. Your main.cf will look like this:
Check Postfix status by executing the below command:
if this command returns the status running, then Postfix is up and running.
Testing mail server Before testing this setup, ensure you have mapped your mail server user in “/etc/postfix/virtual”. Your virtual file should look like this:
We can apply the mapping by typing:
Restart the Postfix process to be sure that all our changes have been applied:
Go to your Gmail account and send mail to admin@syscotest.com. Mail should be sent successfully, and you should receive mail in “/Maildir/new”.
Configuring and Managing mail servers can be a difficult task for new administrators, but with this configuration, you should have basic MTA email functionality to get you started. The success factor for mail server configuration depends upon how you configure and run your mail server.
Hope this was helpful! 💚