// Tutorial //

How To Install and Setup Postfix on Ubuntu 12.04

Published on January 3, 2013
Default avatar
By Etel Sverdlov
Developer and author at DigitalOcean.
How To Install and Setup Postfix on Ubuntu 12.04

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

About Postfix

Postfix is a free, open source Mail Transfer Agent which works to route and deliver email.

 

Prerequisites

Before installing Postfix, you will need to have a Fully Qualified Domain Name pointing to the server that you will be using.

You can find instructions on that here:How to Set Up a Host Name with DigitalOcean

Install Postfix

Postfix can easily be installed through apt-get:

sudo apt-get install postfix

During the installation, you will see a dialogue box appear, asking you which kind of installation you would prefer. Select “Internet Site”.

Follow up by entering the name of your domain.

Once Postfix is installed there are a few steps that need to be taken before it is fully functional.

Configure Postfix

Once Postfix is installed, go ahead and open the main configuration file.

sudo nano /etc/postfix/main.cf

There are a few changes that should be made in this file.

myhostname = example.com

Put in name of your domain into myhostname.

If you want to have mail forwarded to other domains, replace alias_maps with virtual_alias_maps and point it to /etc/postfix/virtual.

virtual_alias_maps = hash:/etc/postfix/virtual

The rest of the entries are described below

mydestination defines the domains that postfix is going to serve, in this case—localhost and your domain (eg. example.com). relayhost can be left, as is the default, empty.

mynetworks defines who can use the mail server. This should be set to local—creating an open mail server is asking for SPAM. This will usually have damaging effects on your server and may put you in line for discipline from your web hosting provider.

If it is not set up by default, as it should be, make sure you have the following text on that line:

mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

The rest of the lines are set by default. Save, exit, and reload the configuration file to put your changes into effect:

sudo /etc/init.d/postfix reload

Configure Additional Emails

To redirect emails to specific emails, you can add users to the alias file. By default each user on the server will be able to read emails directed to their username@domain-name.com.

Open up the the alias database:

sudo nano /etc/postfix/virtual

Within that file, enter in the names of your users. For example:

sales@example.com username1
me@example.com username2

Once you are finished, save, exit, and run the following command:

postmap /etc/postfix/virtual

The last step is to reload postfix once more.

sudo /etc/init.d/postfix reload

Conclusion

Once Postfix is installed, mail can be sent to and from the server, although without a mail server like Dovecot or Cyrus, you will only be able to see the email on the server.

You send out email from the command line with the command “sendmail” and where you want the mail sent to:

sendmail sample-email@example.org

Once you enter the command, type your message, and when it is completed, you can send it off with ctrl-D

Incoming mail gets delivered into /var/mail/username

By Etel Sverdlov

If you’ve enjoyed this tutorial and our broader community, consider checking out our DigitalOcean products which can also help you achieve your development goals.

Learn more here


About the authors
Default avatar
Developer and author at DigitalOcean.

Still looking for an answer?

Was this helpful?
10 Comments

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

I am getting an error when attempting to install postfix via the command: sudo apt-get install postfix This is the output. I tried updating and running with --fix-missing to no avail: root@ubuntu-512mb-nyc1-01:/etc# sudo apt-get install postfix Reading package lists… Done Building dependency tree Reading state information… Done The following additional packages will be installed: ssl-cert Suggested packages: procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre sasl2-bin dovecot-common postfix-cdb mail-reader postfix-doc openssl-blacklist The following NEW packages will be installed: postfix ssl-cert 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 1,169 kB of archives. After this operation, 3,759 kB of additional disk space will be used. Do you want to continue? [Y/n] y Ign:1 http://mirrors.digitalocean.com/ubuntu xenial/main i386 ssl-cert all 1.0.3 7 Err:2 http://mirrors.digitalocean.com/ubuntu xenial/main amd64 postfix amd64 3.1 .0-3 Could not resolve ‘mirrors.digitalocean.com’ Err:1 http://mirrors.digitalocean.com/ubuntu xenial/main i386 ssl-cert all 1.0.3 7 Could not resolve ‘mirrors.digitalocean.com’ E: Failed to fetch http://mirrors.digitalocean.com/ubuntu/pool/main/s/ssl-cert/s sl-cert_1.0.37_all.deb Could not resolve ‘mirrors.digitalocean.com

E: Failed to fetch http://mirrors.digitalocean.com/ubuntu/pool/main/p/postfix/po stfix_3.1.0-3_amd64.deb Could not resolve ‘mirrors.digitalocean.com

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

thanks very much !

Good tutorial.

How to make so the email received from my droplet will use no-reply@mydomain[dot]something I mean how to set it to be no-reply?

Hi there. I have a small question. With this postfix install and configuration will I be able to send emails through mandrill?

Thanks for the tutorial. I’ve setup postfix on one of my servers and mail is sending but all mails arrive in the spam box (Google). I’ve setup an SPF record for the server (which FQDN is servername.myowndomain.com) like this: v=spf1 a mx ip4:mydropletsip ~all.

Checking the full message I see: Received-SPF: pass (google.com: domain of www-data@myfqdn designates mydropletsip as permitted sender) client-ip=mydropletsip; Authentication-Results: mx.google.com; spf=pass (google.com: domain of www-data@myfqdn designates mydropletsip as permitted sender) smtp.mail=www-data@myfqdn; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com

Who can help me out? Cheers, Jaap

@raju: While it’s largely the same, if you’re using Ubuntu 14.04 you probably want to check out this article:

https://www.digitalocean.com/community/tutorials/how-to-install-and-setup-postfix-on-ubuntu-14-04

As for <code>/etc/postfix/virtual</code> not existing, that is normal. You should create the file with: <pre> sudo nano /etc/postfix/virtual </pre>

Hello, I did the installation for postfix for unbuntu 14.04 64 bit. I am unable to set the configuration defined /etc/postfix/virtual as the virtual file is not available. please clarify if it is a new file we create with any specific extension like .conf or .cf etc… please help out. Thank you

Raju

@kuvopolis: You will need to add an entry for root@domain.com in <code>/etc/postfix/virtual</code> or add a catch-all entry so that all emails sent to anything@example.com will be forwarded to your user: <pre>root@domain.com username1</pre> or <pre>@domain.com username1</pre>

I set up my MX records and followed the steps prescribed above, but when I try to send email to root@domain.com they bounce with the message “Recipient not found”.

I am Arvind chaurasia from Core techies… I want to know how to create Email id with different-2 users. I have already purchased Server…Installed Postfix on server I am totally confused… My domain name is veeprop.com… I want to create Email id like :- info@veeprop.com,noreply@veeprop.com,admin@veeprop.com with different users… I can’t received mail form server… Please help me

Thanks & Regards… Arvind chaurasia