How to setup Postfix mail server on Ubuntu using SquirrelMail

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

sudo nano etc host.png

  /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 host_name

IP_address is the IP address of the host you have found above.

host_name is the name of the host.

Example

To add a host name called net2host, with an IP address 180.0.1.10, add the line below in the /etc/hosts file:

180.0.1.10 net2host

Here is an example input in /etc/hosts file:

127.0.0.1 localhost

180.0.1.10 net2host

Now save the file and cross-check the domain name with hostname –f command. (host here is mai ).

Updating Repositories

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 :

update and upgrade

Read: How to send one-liner emails from Linux/Ubuntu terminal 

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

sudo-apt-get-install-apache2

And now for PHP :

install-PHP

Now you are all set to install postfix and SquirrelMail.

Read: How to install and uninstall applications in Ubuntu ? A Beginner’s guide

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

sudo-apt-get-install-postfix

When it asks to select a mail configuration during installation, select internet site and click ok.

postfix-config

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-configuration-

Postfix service needs to be restarted in order to set up System mail name.

sudo service postfix restart


Read: How to install Apache web server on Ubuntu ?

Preparing Dovecot

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

install dovecot.png

Now restart Dovecot by issuing the command below:

sudo service dovecot restart

dovecot restart.png

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:

wget https://sourceforge.net/projects/squirrelmail/files/stable/1.4.22/squirrelmail-webmail-1.4.22.zip

After downloading the package, extract it using the following command:

unzip squirrelmail-webmail-1.4.22.zip

install SM 2.png

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/

Then,

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.

squirrelMail

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.

 

ziad nahdy

Ziad Nahdy, fan of open source and programming languages. He is a technical writer, blogger and Linux enthusiast. He loves to read and help others with their problems. He is addicted to open source software but he also loves other technology related subjects.

Leave a Reply