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. Much appreciated such a great amount for this data. I need to tell you I agree on a few of the focuses you make here and others might require some further survey, however I can see your perspective. Buy USA Gmail Accounts

    ReplyDelete
  9. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free.
    SubsShop.com

    ReplyDelete
  10. I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people.
    https://zartash.pk

    ReplyDelete
  11. This information is meaningful and magnificent, Which you have shared here about the SMTP server. I am impressed by the details that you have shared in this post and It reveals how nicely you understand this subject. If anyone looking for the Affordable SMTP Server, Mails2inbox is a good choice.

    ReplyDelete
  12. This comment has been removed by the author.

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

    ReplyDelete
  14. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
    Buy aged verified YouTube accounts

    ReplyDelete