Configuring postfix to relay mail to a secure host

I just tried to get one of my Linux boxes to send email through my Web service provider. This turned into a nightmare, as I had to piece together advice from four or five different pages.

So here are the real instructions:

  1. Install Postfix, Cyrus-SASL, and the necessary support stuff including OpenSSL.
  2. Your /etc/postfix/main.cf file needs to have lines like this: relayhost = [mail.foo.com]:999 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_type = cyrus smtp_use_tls = yes Special notes:
    • Do not forget the square brackets around the relay host name, or your Postfix installation will do an MX lookup on the name, then connect to the mailserver that comes back from the MX. This is probably not what you want, if the relayhost is your ISP’s mail server.
    • Obviously, if your ISP doesn’t block port 25 you don’t need to specify port number 999 (or whatever) in the relayhost line. But is there an ISP that doesn’t block port 25, these days?
  3. Create a password file by editing /etc/postfix/sasl_passwd and adding a line like this: [mail.foo.com] username:password Again, don’t forget the square brackets or you may be screwed.
  4. Convert the password file to a DB file by executing postmap /etc/postfix/sasl_passwd
  5. Use postfix reload to reinitialize postfix with your new main.cf file.

Test your mail and make sure it works. Thank god I won’t need to figure this out again!