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

19 comments:

  1. Great post. Worked well for me. I did this on a FreePBX 2.10

    Thank you

    ReplyDelete
  2. I tried this but in the mail log /var/log/maillog I'm getting 554 5.7.1 : Sender address rejected.

    I did not get any errors when I put in all the commands from above. The only thing I did differently was use the smtp.aol.com instead of google. I verified that 587 is still the port. Any ideas?

    ReplyDelete
  3. Just tested it and works, thanks you very much

    ReplyDelete
  4. One the few times I actually used something from the Internet and it worked the first time!!!

    It appears that there is a weakness and too much complexity in FreePBX when it comes to simply sending out emails with Voice Mail Attachments.

    Thank you again for filling in a large gap...

    ReplyDelete
  5. Works for me, many thanks for this.

    ReplyDelete
    Replies
    1. Strangely enough I've tried this on a Zoho account and a Google Apps account and it doesn't work, but it does on my plain vanilla gmail account. I have no idea why that should be?

      Delete
  6. This worked like a champ the first time around with FreePBX/Asterisk 11 with Centos 6.

    ReplyDelete
  7. I almost forgot, I thank you very much.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. This comment has been removed by a blog administrator.

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. This comment has been removed by a blog administrator.

    ReplyDelete
  14. This comment has been removed by a blog administrator.

    ReplyDelete
  15. Work very nice with RasPBX (Raspberry pi)
    - Asterisk 13.20.0
    - FreePBX 14.0.2.10

    ReplyDelete
  16. This comment has been removed by a blog administrator.

    ReplyDelete
  17. When you use a genuine service, you will be able to provide instructions, share materials and choose the formatting style. 2013 Aged/Old Gmail

    ReplyDelete