Apr 21 2009

Configure Postfix with smart host

Tag:tepezcuintle @ 16:45

Postfix mouseAt work i setup a programming environment for developers. The server is on a natted IP address range and could not send email to our internal mail server because of some weird firewall issues.

All email going to external sites was working fine but to send to our internal domain it wouldn’t work so i had to figure out how to get emails out. I am running postfix on the server so what I did i had postfix relay the mail to my ISP’s mail server. I had done this in the past using sendmail but with postfix I had to do the following.

My ISP requires that mail from my dynamic IP to our small business email addresses uses their outgoing SMTP servers. This is probably done to reduce abuse and spam but now I’m not able to send email and local Postfix log file displays authentication failure message. How do I relay mail through my mail ISP servers using Postfix SMTP under Linux / UNIX like operating systems?

Postfix has a method of authentication using SASL. It can use a text file or MySQL table as a special password database.

Configure SMTP AUTH for mail servers

Create a text file as follows:
# P=/etc/postfix/password
# vi $P

The format of the client password file is as follows:

#smtp.isp.com       username:password
smtp.vsnl.in         vivek@vsnl.in:mySecretePassword

Save and close the file. Set permissions:
# chown root:root $P
# chmod 0600 $P
# postmap hash:$P

Enable SMTP AUTH

Open main.cf file, enter:
# vi /etc/postfix/main.cf
Append following config directives:

 relayhost = smtp.vsnl.in
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/password
smtp_sasl_security_options =

Where,

  • relayhost = smtp.vsnl.in : Rely all mail via smtp.vsnl.in ISP mail server.
  • smtp_sasl_auth_enable = yes : Cyrus-SASL support for authentication of mail servers.
  • smtp_sasl_password_maps = hash:/etc/postfix/password : Set path to sasl_passwd.
  • smtp_sasl_security_options = : Finally, allow Postfix to use anonymous and plaintext authentication by leaving it empty.

Save and close the file.

Then run postmap /etc/postfix/password

Restart Postfix:
# /etc/init.d/postfix reload
Test your setup by sending a text email:
$ echo 'This is a test.' > /tmp/test
$ mail -s ‘Test’ you@example.com < /tmp/test
# tail -f /var/log/maillog
# rm /tmp/test