How to Relay Postfix SMTP on Ubuntu

Mail Relay

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.

Requirement:

  • 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:

    smtp.colekcolek.com      email@colekcolek.com:password

  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/main.cf

    And make sure the following lines are exist.

    relayhost = smtp.colekcolek.com
    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 = [smtp.colekcolek.com]:26

  5. Restart Postfix

    $ sudo /etc/init.d/postfix restart

 

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.