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.
Postfix is a free, open source Mail Transfer Agent which works to route and deliver email.
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
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.
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
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
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
Incoming mail gets delivered into /var/mail/username
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
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!
awesome! It worked! thank you. Might want to add “sudo” in the postfix reload section’s and at postmap command. what would you recommend to take it to the next level? Jump into Dovecot?
thanks again
+1 for a tutorial explaining how to add Dovecot to Ubuntu (12.10 ?)
In my case for example, I would have multiple aliases on multiple domains hosted on the VPS. Would be great to learn how to install Dovecot to have each domain get its mail delivered in its own folder. Thanks!
Hi,
I have followed this tutorial and now want to setup SMTP access, how do I do this?
Thanks
Hi. Thanks for this tutorial. Sending went ok, but I am not receiving any email. Question: I have firewall setup as in your security tutorial. Do I have to make changes to it to receive the emails sent to me? Thanks.
Nevermind previous comment. I added a rule to the firewall to allow port 25 and now everything works perfectly.
If wou followed the tutorial on iptables firewall then the steps to add port 25 are:
sudo iptables -L -n –line-numbers
BTW: sudo apt-get install alpine OR mutt will give you the console email client. Brings up memories. :)
If you are using Google Public DNS in /etc/resolv.conf which is the default, you will need to change it as Spamhaus does not work with Google Public DNS servers.
Which IP addresses I can use instead defaults(8.8.8.8,8.8.4.4) in resolf.conf? Because I can only send e-mails, not receive
comcast rejects www-data in from name, how to change?
@Oliver Kriska You can use Level 3’s DNS servers: 209.244.0.3 and 209.244.0.4. @local8 You can pass the From: header in your email in the following format:
From: Name e@ma.il or From: e@ma.il
Hi, how to resolve issue with “root” mail? After postfix installed no mail is delivered to root anymore instead it goes to user “nobody”
@titelskibreg: http://hypert.info/mac/postfix.html please see the “To enable email for the root account:” section.
@Kamal: thank you, dns work, but I can not receive emails. Maybe I have problem with my dns settings. My questions in your forum: https://www.digitalocean.com/community/questions/only-send-e-mail-with-iredmail-on-ubuntu
It worked, thanks now reading https://help.ubuntu.com/12.10/serverguide/dovecot-server.html for dovecot installation…
Thank you for the tutorial it worked great.
A few tips on installing postfix and dovecot (note that I was only interested in smtps and imaps protocols):
Hi ,
Web mail installation total guide step by step how i get. plz help me
@kumarmukesh722: I recommend installing iRedMail, it’s easier for beginners: https://www.digitalocean.com/community/articles/how-to-install-iredmail-on-ubuntu-12-04-x64
When I send email to one of my gmail account, the sender address shown user@domain.com but I’ve defined alias contact@domain.com user. How can I make sender address contact@domain.com?
Thanks
@amar5326: Set the From: header to contact@domain.com. How are you sending the email?
@Kamal Nasser: I followed the guide. sendmail myemail@gmail.com > Enter then type messages > ctrl + D. It got delivered into my gmail inbox but the address from root@domain.com
Nevermind, I got it. Need -f parameter. Now, how can I setup for sending and receiving from my email client? I don’t want webmail. Do you articles for that?
Thanks.
@amar5326: To be able to send and receive mail from your desktop email client, you’ll have to install dovecot (for IMAP) and configure it to work with postfix. Unfortunately we do not have an article on doing that at the moment. I recommend taking a look at iRedMail if you want a full-fleged mail server: https://www.digitalocean.com/community/articles/how-to-install-iredmail-on-ubuntu-12-04-x64
Hello fellows, trying to install Postfix, came to the first screen where it says ‘Package Configuration’ I just can
t go any further. Nothing to click and nothing to do. Can
t even press enter to select OK. What can I do?How do I install Dovekot?
@felix.johnson: Were you able to install Postfix?
You can install dovecot by running the following command:
<pre>apt-get install dovecot-imapd dovecot-pop3d</pre>
Configuration: http://wiki2.dovecot.org/BasicConfiguration
Dear. I am looping at:
/etc/init.d/postfix reload
I got below error when reload postfix at first time:
How can I pass this? I Spent more than 1 week and now DO is still not working properly for Wordpress :|
Thank you
@nguyentien.jobs: Check postfix’s error logs, do you see anything?
<pre>tail /var/log/maillog /var/log/mail</pre>
If you have fail2Ban installed make sure you enable postfix in /etc/fail2ban/jail.conf
Thanks for the tutorial, I have configured postfix as the instructions. Mail working well but it is blocked as spam by Google. How to solve this ?
@raj.amalw: Try adding an SFP record to your domain:
<a href=“https://www.digitalocean.com/community/articles/how-to-use-an-spf-record-to-prevent-spoofing-improve-e-mail-reliability”>https://www.digitalocean.com/community/articles/how-to-use-an-spf-record-to-prevent-spoofing-improve-e-mail-reliability</a>