Configure Smarthost SMTP Authentication on Postfix

My machine at home cannot send email using port 25, end up I got to do smart host SMTP authentication on Port 587 means your machine will connect to your public mail server, and from your public mail server deliver the email to recipient. Let’s do some simple Smarthost SMTP authenication on Postfix. The example is Postfix on Linux Ubuntu server.

Create Authentication Password File For Postfix

Create a password file which require authentication on your mail server.


shell> vi /etc/postfix/smarthosts.conf

#mailserver username password
mail.example.com test 123123

Save the file and perform some simple permission settings.


shell> cd /etc/postfix
shell> chown root:root smarthosts.conf
shell> chmod 0600 smarthosts.conf
shell> postmap hash:$P

Now you have done with SMTP server authentication configuration file.

Configure Smart Relay on Postfix

Fire up Postfix’s main.cf config file


vi /etc/postfix/main.cf

Paste the config below on the bottom of the configuration


relayhost = mail.example.com:587
# smtp_sasl_auth_enable = yes
smtp_auth_enable = yes
# smtp_sasl_password_maps = hash:/etc/postfix/smarthosts.conf
smtp_password_maps = hash:/etc/postfix/smarthosts.conf

relayhost is the your server address and with port 587, in case your ISP is blocking port 25. You can use either plain password authentication or SASL authentication, depend on what type of authentication does your server support.

Save it and reload Postfix Service


shell> /etc/init.d/postfix reload

Perform the testing on your newly configured SMTP Smart Host Authentication


shell> echo 'Hello World' > /tmp/hello
shell> mail -s 'Hello World' test@example.com < /tmp/hello
shell> rm -f /tmp/hello

Check on the mail server log on delivery status.


shell> tail -F /var/log/mail.log
Mar 25 22:42:43 dummyserver postfix/pickup[6747]: 755A441202: uid=0 from=
Mar 25 22:42:43 dummyserver postfix/cleanup[6772]: 755A441202: message-id=<20100325144243.755A441202@dummyserver.WAG160N>
Mar 25 22:42:43 dummyserver postfix/qmgr[6748]: 755A441202: from=, size=305, nrcpt=1 (queue active)
Mar 25 22:42:54 dummyserver postfix/smtp[6775]: 755A441202: to=, relay=mail.example.com[203.222.222.222]:587, delay=11, delays=0.12/0.01/10/0.99, dsn=2.0.0, status=sent (250 OK id=1NuoGu-000PGq-6l)
Mar 25 22:42:54 dummyserver postfix/qmgr[6748]: 755A441202: removed

If the status is sent, it means your smart host is working well.