Postfix relay all mail
A classic configuration!
To configure Postfix to relay all mail, you'll need to modify the main.cf
file, which is the main configuration file for Postfix. Here are the steps:
Step 1: Edit the main.cf
file
Open the main.cf
file in a text editor, usually located at /etc/postfix/main.cf
(on Linux systems).
Step 2: Set the relayhost
parameter
Add the following line to the file:
relayhost = <your-relay-host>
Replace <your-relay-host>
with the hostname or IP address of the mail relay server you want to use. For example:
relayhost = [mail.example.com]:25
This sets the relay host to mail.example.com
on port 25.
Step 3: Set the mydestination
parameter
Add the following line to the file:
mydestination = $myhostname
This sets the local hostname as the destination for mail.
Step 4: Set the mynetworks
parameter
Add the following line to the file:
mynetworks = 127.0.0.0/8 [::1]/128
This sets the local network (127.0.0.0/8) and the loopback interface ([::1]/128) as the only networks that can send mail directly to the Postfix server.
Step 5: Restart Postfix
Restart the Postfix service to apply the changes:
sudo service postfix restart
Verify the configuration
You can verify the configuration by running the following command:
postconf -n
This will display the current configuration settings, including the relay host.
Test the configuration
Send a test email to a recipient outside your local network to verify that the mail is being relayed correctly. You can use a tool like telnet
to test the connection:
telnet <your-relay-host> 25
Replace <your-relay-host>
with the hostname or IP address of the relay host. If the connection is successful, you should see a response from the relay host.
That's it! With these steps, you should now have Postfix configured to relay all mail to the specified relay host.