The postfix mail server is an open-source MTA (mail transfer agent). Postfix routes e-mails to the desired mail server. It was originally released in 1998 and still active in 2019. It is also known as VMailer or IBM secure mail. If you don’t want to use mail servers like G-mail and want to convert your Ubuntu machine into a mail server then you are at the right place. In this article, you will learn to set up a postfix mail server on your Ubuntu PC. Follow the instruction below to set up a postfix mail server on your pc. Keep in mind that I will be using Ubuntu to showcase all the commands but you can use the same commands in Debian or even Mint.
Setting up FQDN(fully qualified domain name)
FQDN is the full domain name for a specific computer, or host that is connected to the internet. The FQDN has two parts: the hostname and the domain name. For instance, an FQDN can be mail.company.com. Below you learn see how to set up a FQDN in Ubuntu :
Type in hostname –f in the terminal to find a domain name.
Type in ifconfig to know your IP address.
As you can see from the snapshot above, you will need to install the net-tools package first. You can do this by performing the following command in the terminal :
sudo apt-get install net-tools
Note down your IP address.
Now type in the following command in the terminal:
sudo nano /etc/hosts
/etc/hosts is just a file that maps IPs to hostnames
Now add a line which contains your IP address and domain in the file /etc/hosts as follows:
IP_address is the IP address of the host you have found above.
host_name is the name of the host.
To add a host name called net2host, with an IP address 18.104.22.168, add the line below in the /etc/hosts file:
Here is an example input in /etc/hosts file:
Now save the file and cross-check the domain name with hostname –f command. (host here is mai ).
First, you will need to update all the APT repositories in your Ubuntu PC. To do so, perform the following commands in terminal:
sudo apt update
sudo apt upgrade
Or proceed as shown here :
Now you need to have Apache2 and php5 in your pc in order to install SquirrelMail. Enter the following command in the terminal: sudo apt-get install apache2
And now for PHP :
Now you are all set to install postfix and SquirrelMail.
Setting up the postfix mail server
Postfix is responsible for sending and receiving e-mails. To install the postfix mail server, enter the following command in the terminal:
sudo apt-get install postfix
When it asks to select a mail configuration during installation, select internet site and click ok.
Enter your FQDN in the provided box. It is used to send mails to net2.com but you will use your yourusername.com, don’t forget to provide a proper domain name.
Postfix service needs to be restarted in order to set up System mail name.
sudo service postfix restart
Dovecot is a Mail Delivery Agent (a POP and IMAP server), written with security primarily in mind. It manages local mail directories and permits users to access and download their mail. It supports the major mailbox formats: mbox or Maildir. Dovecot receives incoming mail from Postfix in order to deliver it. But before the delivery, Dovecot will need to authenticate the connected virtual users over SMTP.
You will need to install Dovecot MDA (mail delivery agent) via the following command:
sudo apt-get install dovecot-imapd dovecot-pop3d
Now restart Dovecot by issuing the command below:
sudo service dovecot restart
Setting up SquirrelMail
This step is essential to carry out.As mentioned earlier, SquirrelMail is responsible for managing e-mails on your server. In order to install it, you first need to download the SquirrelMail package.
Type in the command below to download the SquirrelMail package:
After downloading the package, extract it using the following command:
And then run the command:
sudo mv squirrelmail-webmail-1.4.22 /var/www/html/
Now you need to give all the required permissions to SquirrelMail. Type in the following command in the terminal:
sudo chown -R www-data:www-data /var/www/html/squirrelmail-webmail-1.4.22/
sudo chmod 755 -R /var/www/html/squirrelmail-webmail-1.4.22/
sudo mv /var/www/html/squirrelmail-webmail-1.4.22/ /var/www/html/squirrelmail
Now you will need to configure SquirrelMail via the command below :
sudo perl /var/www/html/squirrelmail/config/conf.pl
Now type 2 and press enter to edit server settings. Then type 1 and press enter to edit domain name.
Now go to the main menu by pressing ‘R’ and then enter.
To enable server-side-shorting, press 4 and then choose option 11 and enable it.
Now press S and enter.
Setting up Mail Users
Now you will need to create a mail user in order to starting using SquirrelMail server. To set up a user name type in the following command in the terminal :
sudo useradd yourusername
Don’t forget to replace yourusername with the desired one.
Now setup the password via:
sudo passwd yourpassword
Now create a default directory for the user:
sudo mkdir -p /var/www/html/yourusername
usermod -m -d /var/www/html/yourusername yourusername
Now, give full permissions to the user by typing in the following command :
sudo chown -R myusername:myusername /var/www/html/myusername
After setting up the permissions you can then log in into SquirrelMail with your user name and password.
The postfix server is a great utility. Type in some command and voila! You have your own mail server. This is a great utility that helps set up your own mail server instead of gmail and yahoo.
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.