SASL to an ISP's SMTP relay on a Postfix email server Debian

A step by step guide

I first learned to set up and administer mail services using Ivar Abrahamsen's excellent guide How to set up a mail server on a GNU / Linux system at Flurdy.com.

During Postfix configuration, the Flurdy guide offers you the option of letting Postfix deliver outbound mail directly to the receiving system, or going through your ISP's relay host. In a perfect world, direct delivery would be the preferred option; however, you will find that some systems will reject your mail based on reverse lookups, as in this example. This is for spam control, and it's annoying, but unless you want to go through all the trouble of getting ISPs and domain registrars to set up PTR records, the easier solution is to just use the ISP relay. This is most likely going to require Postfix to authenticate to the relay, which the Flurdy guide doesn't go into.

So here is a little addition to Flurdy's guide, in a format Flurdy users may find familiar. :)

A word of caution

This guide is not as useful as it once was. Not all ISPs offer relays anymore, so don't assume that one is available just because this guide exists to show you how to use one. My ISP shut down their relay, forcing me to get them to set up a PTR for reverse DNS. So I don't use the configuration shown here myself anymore, and this document is unlikely to receive any further updates.

postfix


Author: Jon Jerome, based on the work of Ivar Abrahamsen
Update: 2016-03-14
Update: 2018-03-30 - Added "word of caution" header.


SASL Configuration for SMTP relay authentication

Open the Postfix main config file

sudo vi /etc/postfix/main.cf

Change the relayhost value to your ISP's SMTP relay address. Most likely the port should be 587:

#This is my relay for Comcast; you should use whatever relay address your ISP provides you here: relayhost = smtp.ch1.comcast.net:587

Add or enable values for smtp_sasl:

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

Save and close.

Now we have to set up and hash the authentication credentials. First make sure you have the required packages:

sudo apt-get install libsasl2-modules

Once that's done, go to the postfix config directory and open a new file to contain your credentials:

cd /etc/postfix sudo vi sasl_passwd

Identify the relay and put your credentials into the file:

smtp.ch1.comcast.net:587 username@isp_domain:isp_mailPASSWORD

So for example if your ISP mail login is bobsmith@bobsmith.comcastbiz.net with a password of abcd1234, you'd put this in the file:

smtp.ch1.comcast.net:587 bobsmith@bobsmith.comcastbiz.net:abcd1234

It's very important that the first part of this line, including the port number, exactly matches the relayhost value you put in the main.cf file.

Now we create the hashed authentication values:

postmap hash:sasl_passwd

If this succeeds, it should create a file called /etc/postfix/sasl_passwd.db.

Restart the Postfix service to apply the changes:

service postfix restart

Testing

To test, tail the mail.info log and send a piece of outbound mail. You should see the ISP's relay accept it:

Mar 14 13:15:33 Hostname postfix/smtp[18894]: 396444A0177: to=<someone@somewhere.com>, relay=smtp.ch1.comcast.net[68.87.20.12]:587, / delay=0.65, delays=0.02/0.01/0.4/0.22, dsn=2.0.0, status=sent (250 2.0.0 VuFZ1s6yyw46u78jdyhe46 mail accepted for delivery)

If you do NOT see that, you'll see a rejection response from the relay instead. Usually the error will tell you what is amiss; most often it's just that you have the password or username wrong.

For general testing procedures, see the testing section of the Flurdy guide.

Author

Jon Jerome, longtime contracting consultant. I spend my day at work staring at glowing rectangles and then come home and do it some more, for fun. Go figure.

If you find an error in this guide, or have suggestions for making it better, you can contact me here.

If you're having trouble and want help, in all honesty you'll probably get a faster answer in the Debian Forums, the Ubuntu Forums, or simply by googling, but you can still contact me if you want to. I promise to read it, but I can't guarantee I'll be able to help.

Other Howtos

If you found this guide helpful, you may also like my guide to setting up Dovecot.

Return to top.