Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just bought a dedicated server and I'm trying to install a webserver on it. The server is Ubuntu 10.04. I installed ftp, nginx, php, mysql, bind and now I have to install mail server.

For the mail server I'm using Postfix, because it's recomended on ubuntu.
I installed Postfix with apt-get install postfix but mail() function from php wasn't working. After a little debug I found the way to solve this : I created an empty file /etc/postfix/ and it worked good.

I do have a mx record like this

mail                5M IN A        5M IN MX    1

After that I wanted to forward all e-mails to my GMail address. So I googled for it and I found in the official docs Virtual Domain Host Forwarding

I added these lines in

virtual_alias_domains =
virtual_alias_maps = hash:/etc/postfix/virtual

I created map file and I placed this line in it

I run in terminal

postmap /etc/postfix/virtual
postfix reload

The result: I can send e-mail from php with mail() function, but when I send an email to that e-mail isn't forwarded to my Gmail.

How to solve this?


I also tried this but not working

It works now! But I don't know what the problem was. I just installed "Mail Server" from Tasksel and after that it worked fine. Can anyone tell me what Tasksel installed or that it changed ?

share|improve this question
Have you checked the logs to see how postfix is routing the email – topdog Aug 20 '10 at 13:08
I see "dovecot" in my logs now. Can I see tasksel installed dovecot. Do you think dovecot makes the difference ? – Andrew Aug 20 '10 at 13:22
normal help type info for debugging postfix includes the output from a postconf -n and any pertinent log info – Greeblesnort Aug 20 '10 at 13:22

To investigate what tasksel has/will load use:

$ tasksel --task-packages mail-server                             ~

Most of these are security neutral-- except dovecot. Dovecot is an excellent and very secure IMAP (server-side mail) service. But, it does not belong on a typical webserver, and has nothing to do with sending mail.

What solved your problem is just that taskel ran the following command for you:

sudo dpkg-reconfigure postfix

Since your mail works now, just uninstall dovecot's packages:

sudo aptitude purge dovecot-common dovecot-imapd dovecot-pop3d

Good luck!

share|improve this answer
I reinstalled Ubuntu and installed just bind9 (for MX) and postfix. Email receiving is not working. I tried "dpkg-reconfigure" but still not working. – Andrew Aug 20 '10 at 17:20
What is dpkg-reconfigure doing exacly ? ... I think it just create So I created it manually – Andrew Aug 20 '10 at 17:30
dpkg-reconfigure run the config process for a package. For postfix, the main result is a proper file. But, /etc/mailname is modified as well. To mail to gmail, you need to relay the mail off a publicly addressable mail server. So a public MX record matching your system's mailname (usually defined in /etc/mailname) must exist. It sounds strange to me that you'd have a MX addressable system as a webserver, but you can do that. – user51838 Aug 20 '10 at 19:35
Unless you are running the public DNS for your domain, bind9 will do nothing for you. Register your MX record with your DNS registrar like, or – user51838 Aug 20 '10 at 19:35
I installed bind9 and I host my own DNS. I's simple to setup a MX record – Andrew Aug 20 '10 at 20:07

When you said "I send mail to", do you mean via another external account?

It sounds to me like your local mail delivery (php scripts calling mail()) is forwarding correctly, but your global internet mail delivery for is not flowing to this box.

For that you'll need to make sure you have a MX record on's DNS config that points to your server.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.