How to Install and Setup Postfix on Ubuntu 12.04



Postfix is an open source Mail Transfer Agent that is used to route and deliver electronic email. It attempts to be fast, easy in administering and more secure.

In this tutorial, you will learn how to install Postfix on Ubuntu 12.04.  Before we get down to install postfix, make sure you have a qualified domain name pointing to the server that you are going to use.

Installing Postfix


The installation of postfix on to your virtual private server can be done using the apt-get installer. Here is how it is done:

sudo apt-get install postfix

While installation is at progress, you will be asked to choose the type of installation. Select Internet Site from the options. After that you will have to enter the domain name too.

Configuring Postfix


Now that you have it installed, we will get down to configuring.

Open up the Postfix mail configuration file

sudo nano /etc/postfix/

Below are the changes that have to be incorporated to the main configuration file:

  • Give your domain name to ‘myhostname’
    myhostname =


  • Replace alias_maps with virtual_alias_maps in case if you want to have mail forwarded to other domains. Make sure you have pointed it to /etc/postfix/virtual.
    virtual_alias_maps = hash:/etc/postfix/virtual

Here, I have used, myhostname and for domain name and hostname. You have to replace them with actual values.

Once you update the required fields, your configuration file will almost look similar to this:

soft_bounce             = no
queue_directory         = /var/spool/postfix
command_directory       = /usr/sbin
daemon_directory        = /usr/libexec/postfix
mail_owner              = postfix 

# The default_privs parameter specifies the default rights used by
# the local delivery agent for delivery to external file or command.
# These rights are used in the absence of a recipient user context.
#default_privs = nobody 
myhostname              = 
mydomain                = 
mydestination           = $myhostname, localhost
unknown_local_recipient_reject_code = 550 
mynetworks_style        = host
mailbox_transport       = lmtp:unix:/var/lib/imap/socket/lmtp
local_destination_recipient_limit       = 300
local_destination_concurrency_limit     = 5
virtual_alias_maps      = hash:/etc/postfix/virtual 
header_checks           = regexp:/etc/postfix/header_checks
mime_header_checks      = pcre:/etc/postfix/body_checks
smtpd_banner            = $myhostname 
debug_peer_level        = 2
debugger_command =         PATH=/bin:/usr/bin:/usr/bin:/usr/X11R6/bin         xxgdb $daemon_directory/$process_name $process_id & sleep 5 
sendmail_path           = /usr/sbin/sendmail.postfix
newaliases_path         = /usr/bin/newaliases.postfix
mailq_path              = /usr/bin/mailq.postfix
setgid_group            = postdrop
html_directory          = no
manpage_directory       = /usr/share/man
sample_directory        = /usr/share/doc/postfix-2.3.3/samples
readme_directory        = /usr/share/doc/postfix-2.3.3/README_FILES 
smtpd_sasl_auth_enable          = yes
smtpd_sasl_application_name     = smtpd
smtpd_recipient_restrictions    = 
                                 permit smtpd_sasl_security_options     = no
anonymoussmtpd_sasl_local_domain         = 
broken_sasl_auth_clients        = yes 
smtpd_helo_required             = yes


Configuration of Additional Emails


Each user on the server can read emails directed to their [email protected] by default. Suppose if you want to redirect emails to particular email, you may add users to alias file.

Open the alias database:

sudo nano /etc/postfix/virtual

Update the names of the users in that file:

[email protected] username1
[email protected] username2

You should substitute the actual user name and domain name in the above mentioned lines.

Save and exit the file.

Now, we are going to set up a database for the postfix to work.

Type in the following command at your terminal:

postmap /etc/postfix/virtual

This command will turn that virtual file into a look-up table and the database will be created for postfix.

Now, reload the postfix:

sudo /etc/init.d/postfix reload

Once postfix is installed, you will be able to send out emails from command line using the ‘sendmail’ command:

sendmail [email protected]

Type in your message and send it off using ctrl+D.

Note: Incoming mails will be delivered to /var/mail/username/



support2 has written 111 articles

Leave a Reply