Thursday, December 13, 2012

Changing FreePBX postfix SMTP server (to Gmail)

FreePBX uses the "postfix" package by default to send emails. This usually works for most people, but since the emails are just being sent directly from the FreePBX machine and not a standard mail server, it is most likely to get flagged as spam.

To lower the chance of messages getting flagged as spam, I setup a Gmail account and used its SMTP servers to send email.

FreePBX Version

I have performed these steps on the FreePBX 1.814 and an earlier distribution. If you're using postfix for email, then these instructions should work for you.


Prerequisites
  • A gmail account created at gmail.com
  • Knowledge of using SSH command line
Instructions
  1. Add the following lines to /etc/postfix/main.cf file:
    /etc/postfix/main.cf
    relayhost = [smtp.gmail.com]:587
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    smtp_use_tls = yes

  2. Create the file /etc/postfix/sasl_passwd with the following contents:
    /etc/postfix/sasl_passwd
    [smtp.gmail.com]:587 [email protected]:password

  3. Restrict permissions on the postfix file:
    chmod 400 /etc/postfix/sasl_passwd

  4. Hash the file into a .db that Postfix will read:
    postmap /etc/postfix/sasl_passwd

  5. Change the owner of the sasl_passwd to the postfix user:
    chown postfix /etc/postfix/sasl_passwd

  6. Reload postfix:
    /etc/init.d/postfix reload