Wednesday 14 December 2016

Install and Configure Postfix as a Send-Only SMTP Server

Setup Postfix as a Send-Only SMTP Server on Ubuntu

Setup Postfix On Ubuntu 16.04

Postfix!! So, Postfix is nothing but a Mail Transfer Agent (aka MTA), an application used to send and receive emails.

Lets start to install and configure it so that you can use it as your email agent for the applications installed on the same server that Postfix is installed on.

Prerequisites:

  1. A Ubuntu Server, setup with sudo non root user.
  2. A domain name assigned with server's IP address, on which Postfix will be installed.
So, after done with all prerequisites, lets move forward for installation of Postfix.

Install Postfix:

Step 1: First update all the packages, came by default with server.

sudo apt-get update

Step 2: Now, install Postfix. For this, we will install mailutils, as it will also install some other required packages for Postfix.

sudo apt install mailutils

While the installation process, you will get prompt like below image


The default option is Internet Site. We will be continuing with default one only. So press TAB then ENTER.

After that, one another prompt will get open as image below:


It will ask you for system mail name. It should be the same as the name you assigned to the server when you were creating it. If its showing subdoamin name by default, for example abc.example.com then change it to example.com. Now, press TAB then ENTER.

Postfix installation process is finished here. Now lets continue with Configuration

Configuring Postfix:

Here shown setting is to send emails from localhost application that is applications installed on the same server as Postfix. Lets begin configuration.

Step 1: To allow Postfix to server only localhost application, it must listen only on loopback interface. It allows server to communicate internally. For this, open the main configuration file for Postfix situated at /etc/postfix/main.cf.

sudo vi /etc/postfix/main.cf

Change the value for inet_interfaces from all to as follow:

inet_interfaces = loopback_only

Note: If loopback_only setting is giving error then replace it with localhost. For example:

inet_interfaces = localhost

Step 2: To specify the list of domains that are delivered via localhost_transport mail delivery transport, change the value for my_destination as follow:

mydestination = $myhostname, localhost.$mydomain, $mydomain


Now save and close the file.

Step 3: Now, restart the Postfix.

sudo systemctl restart postfix

Now you are installation and configuration part of Postfix. To test it, follow the below steps.

Test Postfix

For sending test emails, we will use mail command, which came by default with mailutils package. To send test email, issue following command:

echo "This is the body of the email" | mail -s "This is the subject line" your_email_address

Remember to replace your_email_address with valid email address. Now check the mail in Inbox or Spam box of email address, you provided in above command. Notice the From field of email will be your_server_username@server_hostname. For example user@example.com. If you will change user on the server, the From filed will get update accordingly.

The last thing to setup is forwarding the emails on your personal or external email account as well.

Forwarding System Mail:

To configure Postfix so that system-generated emails will be sent to your email address, you need to edit the /etc/aliases file.

sudo vi /etc/aliases

Replace the value for root as follow:

root: your_email_address

Replace your_email_address with your own private or external email address. 

For changes to take effect, run:

sudo newaliases

Now, Test it by sending email on root account, as follow:

echo "This is the body of the email" | mail -s "This is the subject line" root

You should receive the email at your email address. If not, check your spam folder.

And You are Done.

1 comments:

  1. Nice post. How to secure the postfix server with user name and password?

    ReplyDelete

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel