How to make Postfix relay mail to the servers specified as MX, not to itself

Posted on 2007-10-09
Last Modified: 2008-01-09

I have a machine with Postfix that I want to use for one of my scripts to send mail, to the same domain. It's kind of confusing for me, but here it is:

Let's say the machine name is, and the MX entries of the domain are setup for Google Apps (so Google handles all my mail).

So, currently if I try to send mail from inside the machine, I get a 'user not found' error from postfix, since it tries to deliver mail locally, instead of using the servers specified in the DNS.

Is there an easy way to fix this?

Question by:ivanvega
    LVL 30

    Accepted Solution

    It is very easy you can add this command:
    edit your
    add this command:
    relayhost = Your_mx_host_name

    save & exit. Then restart your postfix:

    # postfix reload

    and that is it.

    If you wanto to relay only your domain to another server then change
    /etc/postfix/virtual and add this line to this file:        @relay_host_name

    save & exit. Then you need to create the binary file with these commands:
    # cd /etc/postfix
    # postmap virtual

    Don't forget to restart your postfix:
    # postfix reload


    Author Comment


    I tried your first suggestion and it still doesn't work:

    "Recipient address rejected: User unknown in local recipient table"

    And my system doesn't have a /etc/postfix/virtual file.


    Author Comment

    It seems if I change myhostname and mydomain too (,, it now works.

    relayhost also accepts the actual domain, instead of a given MX host, and then it will select the right MX entry. Nice.

    LVL 30

    Expert Comment

    by:Kerem ERSOY
    ok. Don't forget to modify your /etc/hosts too. Remove your hostname as an alias to localhost add its own address such as:             localhost.localdomain localhost
    <ip_of_your_ethernet>   nullhost

    save & exit.

    You can just create /etc/postfix/virtual if it does not exist. But in the default  configuration there exists a virtual file with lots of commensts. It is possible that your default config is not in /etc/postfix. if it is just create yourself. it is a text file afterall..

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Microsoft Outlook is not just an email client but it is full featured Personal Information Manager. But sometimes Outlook gets disconnected and you simply can’t access it. What steps can you perform before calling IT support? In this article we will…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now