We now configure Postfix so it relays the email to another server, in our case it will be a Microsoft Exchange Server. We start by editting the following file:
/etc/postfix/main.cf
Find:
mydestination = $myhostname, localhost.$mydomain, localhost
Change it to:
mydestination =
Find:
#local_recipient_maps =
Change it to:
local_recipient_maps =
Find:
# - You redefine the "local_transport" setting in main.cf.
Add a new line just below the above and paste:
local_transport = error:local mail delivery is disabled
Find:
#myorigin = $mydomain
Add a new line just below the above and paste. (you need change Matrix7.com.au to your domain):
myorigin = Matrix7.com.au
Find #mynetworks = hash:/etc/postfix/network_table
Add a new line just below the above and input the following:
mynetworks = 127.0.0.0/8, 192.168.0.0/24
I have added the 192.168.0.0/24 to allow internal machines access to the gateway to send email through it. Either remove this or change the IP to suit your internal network.
Go to the end of the file and add:
parent_domain_matches_subdomains = debug_peer_list, smtpd_access_maps
Find:
#relay_domains = $mydestination
Add a new line just below and add the domains you plan to accept email for as in the following example. Each new domain needs to be separated by a comma:
relay_domains = Matrix7.com.au, domain2.com, domain3.com
Go to the end of the file and add:
smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination
Go to the end of the file and add:
transport_maps = hash:/etc/postfix/transport
Go to the end of the file and add:
show_user_unknown_table_name = no
Go to the end of the file and add:
virtual_alias_maps = hash:/etc/postfix/virtual
Go to the end of the file and add:
message_size_limit = 10240000
You can change the above value of 10240000 to whatever you like. It is basically there to limit the size of emails the server will accept before rejecting them.
Now save and close /etc/postfix/main.cf file.
We'll now edit
/etc/postfix/master.cf
Find:
local unix - n n - - local
Simply comment out the line above. This is so we disable delivery of mail locally to the server itself. We are using it as a gateway/relay so no need for local delivery. The line should now look like:
#local unix - n n - - local
Now save and close /etc/postfix/master.cf file.
We'll now edit
/etc/postfix/virtual
This file is basically used to map "local" email addresses to real email addresses. Go to the end of the file and create the following. (change yourdomain.com to your actual domain. Ensure that the recieveing email exists on your target email server):
postmaster [email protected]
abuse [email protected]
root [email protected]
Now save and close /etc/postfix/virtual file.
Edit the file /etc/postfix/transport
This file is the place where you will tell Postfix to which email server you want the email directed to. It can be on any port and any IP Address. Go to the end of the file and add the following:
Matrix 7.com.au smtp:192.168.0.6:25
domain2.net.au smtp:192.168.0.5:25
domain3.com.au smtp:125.126.127.128:27
Just change the domains and IPs to include your domains and IPs/subnets.
Finally we need to create the db hash databases. To do this execute the following command from your console or Putty:
postmap hash:/etc/postfix/virtual postmap hash:/etc/postfix/transport
If you've done this correctly you should see 2 new files created in your /etc/postfix folder. One called transport.db and the other virtual.db. Please be aware that everytime you add a new domain to your /etc/postfix/transport file you'll need to execute:
postmap hash:/etc/postfix/transport
For the changes to take effect. Same goes for the /etc/postfix/virtual file.
Now restart postfix by using
service postfix restart
You've now completed the Postfix relay portion of the configuration...
Go to Part 4