Postfix - installation

The base package for all the mail articles will be postfix. There are, of course, alternatives to postfix, each with advantages and disadvantages and, without going into the differences, I have chosen postfix due its relative ease of configuration.

As many of the future articles will concentrate on administrative issues and assume postfix is already installed, let's go ahead and install it.

Following from preparing the Slice for our email setup, we can move onto installing postfix.


Installation is very easy (remember we are using Ubuntu Hardy for these articles):

sudo aptitude install postfix telnet mailx

Note that we also install telnet and mailx as they contain several tools we'll use to test and configure postfix.

During the installation you will be asked the general type of mail configuration:

Postfix - installation type

Choose the 'Internet Site' option.

You will then need to enter your main domain name (this should match the hostname we set in the previous article):

Postfix - Setting the domain name



At this stage, you can send emails from your application.

The preparation we did in the previous article and the settings shown above during the postfix installation mean that the very basics are already done.

Quick test

Although we will look in more detail at sending mail in the next article, let's conduct a quick test to see if postfix is actually sending mail.

You will need to send an email to a working email address using the 'mail' command:


Replace the email address with one of your choosing (remember this must be a working email address).

The output asks for the subject of the emai. Once done, press enter/return.

Next enter the subject of the email. Once done, press enter/return and then a single period (.) - the period lets mail know the body is finished.

Finally press enter/return again to send the email (you may need to do this twice so you skip the 'CC:' entry.

The output on my machine looks something like this:

Subject: test email from
test body of the email.

No confirmation is given that the email has been sent (the logs will show the details) but...

You've got mail

Check the receiving email address and voila! a nice, fresh email with the subject 'test email from'.

For many people, that is all you need to send mail from your application - especially if the only emails are notifications to the site administrator.

However, the next article will look in more detail at the settings in postfix's file and what they mean. This can help in reducing the chances of your email being classed as spam or your Slice IP being blocklisted.


Installation of postfix is very simple using the aptitude package manager.

Once installed, email can be sent straight away.


Article Comments:

Jose commented Tue Jul 29 11:44:34 UTC 2008:

Very nice and simple postfix installation. Ive been struggling with having virtual users postfix,courier and mysql.... Keep it up

mchughs commented Wed Jul 30 07:45:30 UTC 2008:

Remember to open up the ports in you firewall, if you have one running, and RESTART postfix.

I drove myself nuts with not being able to receive/send mail even locally(with a full address of course).

Postfix was pretty simple, it's making sure DNS/ReverseDNS and the firewall is setup properly. I hope this helps.


PickledOnion commented Wed Jul 30 09:12:40 UTC 2008:


Please note if you have followed the Slice setup articles (i.e. have not stopped outgoing traffic) you DO NOT need to open a port in the firewall to send emails.

Each article is very specific and this one is about the installation of Postfix.

When we get to the articles on receiving emails we will look at the firewall and what needs doing (with pop and imap as well).

I hope that helps but please keep in mind that, as I say, each article is very specific and deals with small sections of the whole mail setup at a time.


Arul commented Wed Jul 30 19:52:24 UTC 2008:


Thanks for the tutorials, they are very easy to follow.

I have a question about this Postfix installation for multiple domains. I just installed Postfix on my slice and have more than 1 domain. How do I configure Postfix with each domain? Right now, the test email I sent to myself had this autoformat

How do I set it for multiple domains? Thanks!


PickledOnion commented Thu Jul 31 09:45:18 UTC 2008:


I will do an article (or two) on multiple domains.

At this early stage in the email series I am concentrating on the basics and am using a single domain only.

Hang in there - there will be a lot more coming :)


kamal thakur commented Tue Aug 19 19:12:03 UTC 2008:

Hey. I did try to install as told

I am getting this:

The following packages are BROKEN: exim4 exim4-config The following packages will be automatically REMOVED: exim4-daemon-light .... .... Remove the following packages: exim4 exim4-base exim4-config

Score is -819

Accept this solution? [Y/n/q/?] q

I am rebuilding whole thing once again. Hope nothing goes wrong this time.

These packages have something to do with mysql? because last time I did follow all the steps and finally got my mysql.sock file lost.

I have not install any other package and have done exactly as mentioned for Ubuntu Hardy articles one by one.

Dash commented Sun Aug 24 05:47:43 UTC 2008:

Thank you so much PO, am just following the sequences of setting it up - this is very cool and easy to follow. Thank you once again for all your articles!

Glen commented Thu Aug 28 23:58:27 UTC 2008:

Thanks rock!

Matt commented Tue Sep 16 22:36:16 UTC 2008:

Is there a clean way to reinstall Postfix? I have it running, but I never saw those shell prompts during the install. Can I either reinstall or find the appropriate values (internet site and system mail name) in a config file?

jc commented Wed Sep 17 05:38:37 UTC 2008:

I had exim on my machine and it was hell to remove. helped, but I'm not sure what I did was really all best practice.

Tony commented Sun Oct 26 04:49:51 UTC 2008:

I followed the articles to the "T" but when I sent an email it formatted the from address as "". How do you get it so it just shows ""?

Paul commented Sun Oct 26 16:22:43 UTC 2008:

Tony I had the same thing but it resolved itself once I made the changes to the file outlined in the next article.

David McLaughlin commented Thu Nov 06 00:14:33 UTC 2008:

I've tried to set up forward accounts using postfix. When I send a mail via my SSH shell to then it is delivered to my gmail inbox (and not marked as spam).

However, when I send mail to the same address via gmail I'm not getting the forward. What could be causing this?

Cedric commented Thu Nov 13 22:04:49 UTC 2008:

I set-up Postfix and it seems to work as described. On my website, I subscribed using an email account (hosted at Google Apps) that has the same domain that Postfix is set-up for. (The goal is to have the website send confirmation emails or forgotten passwords, while actual user account live on GAFYD.) When the site sends an email, it goes straight into the local shell account on the web server. Is there any way to get these emails to go to the desired GAFYD email account instead?

mdgrech commented Sun Dec 07 04:22:30 UTC 2008:

I love ubuntu server. This is my first server setup. I've been flying through the tutorials and I'm stoked!

Adam commented Mon Dec 29 18:25:15 UTC 2008:

I followed the prepare step for hostname and RDNS, then installed postfix as above. However there was no configuration screen. It seems to skip that step:

-- Setting up postfix (2.5.1-2ubuntu1.2) ...

Postfix configuration was not changed. If you need to make changes, edit /etc/postfix/ (and others) as needed. To view Postfix configuration values, see postconf(1).

After modifying, be sure to run '/etc/init.d/postfix reload'.

I'm assuming its best then to configure this manually as per the next tutorial?

Andrew B commented Mon Jan 12 00:15:25 UTC 2009:

Hello, I see you made the following statement at the end of this tutorial... "Installation of postfix is very simple using the aptitude package manager."

Is there any difference if you use apt-get install rather than aptitude install ??

Thanks! Great tutorials!

Richard W commented Sun Feb 22 18:30:32 UTC 2009:

I just followed this (and the previous two) guides, and the only problem I saw was that during my postfix installation, I was NOT presented with the two configuration screens. Installation completed with no interaction.

Hopefully it still works... on to the next guide!

Russell commented Thu Feb 26 19:08:58 UTC 2009:

Followed the tutorial and things seemed to be OK, but when I did the test mail send, I got "postdrop: warning: unable to lookup public/pickup: No such file or directory"

Russell commented Thu Feb 26 19:13:08 UTC 2009:

Also, is it possible to have both sendmail and postfix installed? I had sendmail installed just for some PHP scripts to easily send mail from the server, but installing postfix asks me to remove sendmail.

Warren commented Mon Mar 23 00:59:40 UTC 2009:

For everyone who didn't get prompted to configure Postfix -- you can ask Ubuntu to ask you again with this command: sudo dpkg-reconfigure postfix If you've already customized your configuration, you might not want to do this.

Jeff commented Tue Jun 02 02:27:33 UTC 2009:

is one of the better walkthrews I have seen, good job Slicehost!

Qualos commented Thu Jul 02 04:49:26 UTC 2009:

@RUSSELL, make sure that you don't have another MTA running. That error usually appears if you recently had another mta (like sendmail) installed before installing postfix. Kill the running MTA, restart postfix, and all should be good.

Drew commented Mon Oct 12 17:07:17 UTC 2009:

To Cedric and anyone else running into the problem of mail bouncing because it is sent to your own domain:

  1. Set your system hostname to something that is not your domain name. For example, if your domain name is, do not set your hostname to If you need to change your hostname be sure to adjust /etc/hosts accordingly and reboot.

  2. Edit your /etc/postfix/ file and set myorigin to your actual sending domain name (so your emails don't come from you@hostname):

myorigin =

(you could also just edit /etc/mailname and change it to if you want to stay more modular)

  1. myhostname and mydestination should both show your new hostname, not your domain name. Adjust them accordingly.

Restart postfix and you should be able to send mail to addresses at with as the sender without the messages bouncing internally.

MikeInAZ commented Sat Oct 24 16:53:47 UTC 2009:

If you're having trouble sending a test, it might be due to your ISP. I'm with Cox and they block port 25. When I switch to my mobile card, I can send.

Barry B commented Sun Oct 25 03:35:02 UTC 2009:


I love these tutorials and all was looking good up until I tried to send mail -- I get the right prompts but nothing seems to happen (that is, I don't receive anything at my gmail account). I'm pretty sure I've set up everything correctly, starting with Hardy Heron, through to setting up my spf record. My /var/log/mail.log file seems, to me at least, to not show any problems -- at least nothing obvious. It all looks like it should have worked. The only thing I can think of that is different from the examples is that my hostname and reverse DNS name I've set to, which is my domain, rather than, because I intend to use my slice for more than just email. It seems to me, based on other posts, that I can do this.

Any suggestions as to what to do next?? I'm not sure how to proceed from here.


Barry B commented Sun Oct 25 06:41:09 UTC 2009:

Okay, I see that it's sort of working after all -- it's just that my messages are being flagged as spam. I'm going to put the "mail" prefix in front of my domain name, and set my hostname to this as well, so that I have a fqdn and completely match the tutorial, and I expect that to work, based on everything I've read -- I'll see soon enough, in 24 hours or so... But what I don't understand is, this seems strange to me, that the reverse dns should show "mail" before the domain name, and that my hostname should be set to mail as well, when I'm using this IP address to host other services too -- a Web server at the very least. Is this the standard thing to do? It may well be -- I'm quite new at this. Or is there another way I'm supposed to get outgoing messages not flagged as spam? Thanks!

Jacob commented Wed Jan 27 16:36:09 UTC 2010:

When installing postfix, I got this error because exim (the existing mail agent on my slice) failed to remove itself properly:

dpkg: error processing exim4-daemon-light (--remove): subprocess pre-removal script returned error exit status 3

Removing the /var/run/exim/ file fixed the issue.

The solution comes from this discussion:

Brian commented Tue May 11 22:03:08 UTC 2010:

Great tutorials! For this one on Ubuntu 10 in order to install "mail" I had to do a

sudo aptitude install mailutils

not "mailx". Also to send the mail using the "mail" command I didn't have to do the period thing, I had to hit Ctrl+D. Hope that helps someone!

David commented Mon Jun 07 03:46:00 UTC 2010:

Thanks Brian. Helped me! Apparently there is more than one mailx virtual package. Aptitude outputs: "mailx" is a virtual package provided by: mailutils heirloom-mailx bsd-mailx You must choose one to install.

Matt commented Tue Aug 24 00:30:18 UTC 2010:

After installing, I can send mail using the mail command from terminal. However, if I run "postfix check", I get:

error: to submit mail, use the Postfix sendmail command fatal: the postfix command is reserved for the superuser

I also get this in my mail log when I try to run the PHP mail() function from a script on my slice.

Jered commented Tue Aug 24 04:25:47 UTC 2010:

For the postfix check command, you'll need to use sudo to run it as the superuser, as in: "sudo postfix check".

Not sure what would cause that error message to show up in PHP logs.

Roberto Ostinelli commented Fri Sep 03 11:51:54 UTC 2010:

dear all,

if you use google apps on your domain you might be interested in this.

following this excellent guide, you set up postfix to both send and receive emails. however, if you use an external mail management like google apps, you will not be able to send out emails from postfix to your google apps, simply because postfix will try to send it to its local boxes and will not find any.

what you just need to do is edit /etc/postfix&my.conf and ensure that the line mydestination = .. does NOT contain your full domain name.

for instance:

mydestination = localhost, mail,

should just read

mydestination = localhost, mail

hope this helps.



Stefan commented Fri Sep 24 17:55:08 UTC 2010:

My test didn't work until I input a message for the test. For some reason if I put in a subject, hit return, put a period, and hit return, nothing happend--but if I put in a subject, hit return, entered a message, hit return, entered a period, and hit return, I got the email to go through.

JH commented Tue Oct 05 02:34:04 UTC 2010:

Hmm, not sure why, following this to a T but I get (ubuntu lucid):

me@mail:/$ mail -bash: mail: command not found

... Any ideas? Did I miss something somewhere...

JH commented Tue Oct 05 05:15:46 UTC 2010:

Ack - sudo apt-get install mailutils fixed my issue...

Godegisel commented Mon Nov 08 06:32:14 UTC 2010:

I was also told 'unable to lookup public/pickup: No such file or directory' when testing my Postfix.Should I uninstall Sendmail?

Jered commented Mon Nov 08 15:52:19 UTC 2010:

Godegisal, it is a good idea to uninstall Sendmail if you install another mail transport agent like postfix. The two programs will compete for some resources (like the SMTP port), so they don't co-exist very well. Be sure to stop Sendmail before uninstalling it. I've seen people have some trouble with a lingering Sendmail process running even after the uninstall on a couple distributions.

David Henley commented Tue Jan 11 18:39:31 UTC 2011:

I got the 'unable to lookup public/pickup: No such file or directory' error.

To fix I did the following:

mkfifo /var/spool/postfix/public/pickup ps aux | grep mail sudo /etc/init.d/postfix restart

then I tested sending a message again and it worked

kumar commented Thu Aug 11 15:00:41 UTC 2011:

Hi, I followed this article and made server successfully. But still i have few probs,

  1. How to communicate the server through thunderbird (i tried & failed)
  2. Is this suecured & else what to do

Jered commented Fri Aug 12 19:01:50 UTC 2011:

If you're trying to use the server to send email then you'll probably need to make some more changes to the server. You'll want to look into some of the settings in like "inet_interfaces" and "mynetworks". You might also look into using postfix with SASL to set up a login for your SMTP server.

Z commented Wed Dec 07 04:11:35 UTC 2011:

If you are using sendmail, when doing "mail" you use CTRL+D instead of the "." to end the body

Want to comment?

(not made public)


(use plain text or Markdown syntax)