How to Relay Postfix SMTP on Ubuntu

Mail Relay

Relay SMTP usually used by mail server with dynamic IP address. In this guide, I will show how to setup relay SMTP on Postfix.


  • Postfix installed on Ubuntu
  • SMTP server (you can use ISP’s SMTP)
  • email address and password to login to SMTP server

How to:

  1. Create password map file

    $ sudo nano /etc/postfix/sasl_passwd

    Type in your SMTP server, username (email address), and password into the file:

  2. Set permission to password map file, so it cannot be read by other user.

    $ sudo chown root:root /etc/postfix/sasl_passwd
    $ sudo chmod 600 /etc/postfix/sasl_passwd

  3. Create hash from map file (remember to do it each time you change your map file):

    $ postmap /etc/postfix/sasl_passwd

  4. Edit Postfix config file

    $ sudo nano /etc/postfix/

    And make sure the following lines are exist.

    relayhost =
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_auth_enable = yes
    smtp_sasl_security_options = noanonymous

    If your ISP blocks outgoing port 25, you can choose to use alternative ports by modifying this line:

    relayhost = []:26

  5. Restart Postfix

    $ sudo /etc/init.d/postfix restart



  • smtp ICON
  • mail ikon
  • mailbox icon

Leave a Reply

Your email address will not be published. Required fields are marked *