Wednesday, February 18, 2015

[Ubuntu]: How to Setup a Complete Mail Server (Postfix) using ‘SquirrelMail’ (Webmail) on Ubuntu/Debian

How to Setup a Complete Mail Server (Postfix) using ‘SquirrelMail’ (Webmail) on Ubuntu/Debian


Creating a mail server on Linux powered machines can be one of the most essential things that every system administrator needs to do while configuring his servers for the first time, if you don’t know what it means; it’s simple, if you have a website like “example.com”, you can create an email account like “username@example.com” to use it to send / receive emails easily instead of using services like Hotmail, Gmil, Yahoo Mail.. etc.
Setup Postfix Mail Server in Debian
Setup Postfix Mail Server in Ubuntu/Debian
In this article, we’ll learn how to do so by installing the Postfix with “SquirrelMail” webmail application and its dependences on Debian/Ubuntu machines.

Step 1: Installing Apache2 and PHP5

1. In order to create a running mail server using “SquirrelMail”, we’ll have to install both Apache2 &PHP5 packages first, to do so, run.
$ sudo apt-get update
$ sudo apt-get install apache2 php5
Install Apache and PHP in Ubuntu
Install Apache and PHP

Step 2: Installing Postfix Mail Server

2. Postfix is a mail transfer agent (MTA) which is the responsible software for delivering & receiving emails, it’s essential in order to create a complete mail server.
To install it on Ubuntu/Debian or even Mint, run:
$ sudo apt-get install postfix
During installation, you will be asked to choose the default file configuration for your server.
Postfix Configuration in Ubuntu
Select Postfix Configuration
3. Next, it asks you to select type of mail configuration, choose “Internet Site”.
Select Mail Configuration
Select Mail Configuration
4. Now enter the fully qualified domain name that you want to use for send and receive mails.
System Mail Name
Enter System Mail Name
5. Once the FQDN set, you’ve restart the Postfix mail server using.
$ sudo service postfix restart

Step 3: Installing Dovecot

6. Dovecot is a mail delivery agent (MDA), it delivers the emails from/to the mail server, to install it, run the following command.
$ sudo apt-get install dovecot-imapd dovecot-pop3d
Install Dovecot in Ubuntu
Install Dovecot
During the installation process, you will be asked if you want to create a self-signed SSL certificate, choose Yes.
Create Mail SSl Certificate
Create Mail SSl Certificate
7. Next, enter your host name to use in the SSL certificate.
Enter Hostname to use SSL
Enter Hostname to use SSL
8. Next, restart Dovecot service using the following command.
$ sudo service dovecot restart

Step 4: Installing SquirrelMail

9. SquirrelMail is the email server that you’ll be using to manage emails on your server, it has a simple web interface to do the job, it can be customized by installing more modules & themes.
$ sudo apt-get install squirrelmail
install squirrelmail in Ubuntu
install Squirrelmail
10. After the installation, you will have to run this command in order to configure SquirrelMail.
$ sudo squirrelmail-configure
Configure Squirrelmail in Ubuntu
Configure Squirrelmail
11. Next, enter “2” in order to edit the server settings, and you will be prompted to it.
Configure Server Settings for Mail
Configure Server Settings for Mail
12. Now enter “1” in order to change the domain name and write up your domain (e.g: example.com).
Set Mail Domain Name
Set Mail Domain Name
13. Go back to the main menu by writing “R” and hitting the enter key, write “4” in order to configure the general options.
Configure Mail General Optionsb
Configure Mail General Options
You see “Allow server-side sorting”? Enter “11” and change it from “false” to “true” by entering “y”. Now hit the Enter key, and enter the “S” key in order to save the configuration file.
Now, we’ll copy the default configuration file to the apache2 directory in order to be able to access the web interface, run.
$ sudo cp /etc/squirrelmail/apache.conf /etc/apache2/sites-available/squirrelmail.conf
And enable it using:
$ sudo a2ensite squirrelmail.conf
14. You can now access the mail server by going to example.com/squirrelmail.
Access Squirrelmail in Ubuntu
Access Squirrelmail

Step 5: Creating Mail Users

15. In order to start using squirrelmail webmail, you’ll have to create a new user, to do so, run.
$ sudo useradd myusername
Replace “myusername” with the user name you want, create a password for the new user by running.
$ sudo passwd myusername
16. Create a home folder for the user in /var/www/html/myusername and make it default home directory.
$ sudo mkdir -p /var/www/html/myusername
$ usermod -m -d /var/www/html main
17. Now go back to the login page and enter the user name and the password of newly created user.
Access Squirrelmail in Ubuntu
Access Squirrelmail
You will be surprise to see the following error message.
Login to Squirrelmail
Login to Squirrelmail
This is just a problem in the permissions, you have to give the user “myusername” the complete permissions on its home folder.
$ sudo chown -R myusername:myusername /var/www/html/myusername
18. Once permission set, you should able to login into squirrelmail.
Squirrelmail Mail Interface
Squirrelmail Mail Interface
You can try to send email from it, or you can try to receive emails by sending it to “myusername@example.com” , don’t forget to replace “myusername” with the user name you created.
If you faced any other error.. Just check the “/var/log/mail.err” file, all the error message will be stored there, you won’t lose your way :)

No comments: