Postfix Relayhost Example

Relay host is defined as a server to which your emails are sent first from your server before being delivered to the actual recipient’s server. It is also known as a smart host. It is known so because this server is efficient and intelligent enough to know the correct relaying destination. A question that normally arises in the mind of a layman is that why do we even need to use a relay host or a smart host in the first place when we can directly transfer the emails from the sender’s mail server to the recipient’s mail server? Doing so will only increase the complexity and the time taken for the email to reach from the source to the destination.

Well, we will try to clear out this ambiguity with the help of a use case. At times when many users start creating their mail servers, some of those mail servers might be labeled as spam servers. And hence it will get impossible to relay the emails to the recipients through these servers. Therefore, it is highly advisable to use a trusted, smart host or a relay host in between which ensures the timely delivery of your emails and also gives you the surety that your emails will not be marked as spam in any way.

The relay host or the smart host can be used with all the mail servers; however, for the course of this discussion, we are only concerned with the Postfix server. Although, the Postfix installation process allows you to choose the mail server configuration of the Satellite System through which you can easily send your emails via a relay host. However, if you have not chosen this option at the time of installation, even then, you do not have to worry about it because you can configure it later on as well. Therefore, today, we will talk about the method of configuring the Postfix relay host after its installation.

Method of Configuring Postfix Relayhost:

For configuring Postfix for using relay host, you will need to perform the following steps:

  • Launch the terminal in Ubuntu 20.04. The configurations for this method are really quick and simple. All we have to do is to make some changes in the /etc/postfix/ file. For doing that, we need to open this file with any text editor of our choice. In this example, we will be using the Nano editor. You can choose any other text editor as well. Now type the following command in your terminal and then press the Enter key to open the /etc/postfix/ file:
sudo nano /etc/postfix/

This command is also shown in the image below:

  • As soon as this command will execute successfully, the /etc/postfix/ file will open up in the Nano editor as shown in the following image:

  • Now scroll down to the relay host entry and type in the IP address of the server that you want to be used as the relay host or the smart host. For example, [email protected] and then type port number 587 separated by a colon, as highlighted in the image shown above.
  • Once you have added the relay host entry in this file, scroll down to the end of the file and then add the following lines in it to enable the authentication of your newly added relay host:
#Enable Authentication
smtp_sasl_auth_enable = yes
#Set Username and Password
smtp_sasl_password_maps = static:Chosen-Username:Chosen-Password
smtp_sasl_security_options = noanonymous
#Enable TLS Encryption
smtp_tls_security_level = encrypt
header_size_limit = 4096000
#Enable CA Certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Here, you need to type the username of your choice instead of Chosen-Username and a password that you want instead of Chosen-Password. Rest, you need to copy and paste these lines as it is at the end of the /etc/postfix/ file. It is also shown in the image below:

  • Now save this file so that its contents are updated and exit from the Nano editor by pressing Ctrl+ X. Finally, type the following command in your terminal and then press the Enter key for the newly made changes to take effect:
sudo systemctl restart postfix

This command is shown in the following image:


By following the simple and basic steps described in this article, you can conveniently configure Postfix relay host and hence deliver your emails to the right recipient well in time without the fear of your emails being marked as spam. This method is quite efficient and very easy to follow, as there are just a few lines of settings that you need to add to the Postfix configuration file. After that, you will be all set to relay your emails via a smart host.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.