Configure email service for FreePBX

We will configure FreePBX to send emails through a Gmail SMTP relay. FreePBX will use Postfix of the underlying Redhat Linux system to achieve this.

Create a Google app password

Login to your google account with the email address you want to use for sending the notifications from your FreePBX system. On the Google account management page, click on Security, then on 2-Step-Verification. At the end of that page, create an App Password for your FreePBX system.

Create a password file in CLI

Create or edit the sasl_passwd file:

sudo nano /etc/postfix/sasl_passwd 

Add the following line to it:

[smtp.gmail.com]:587 my_email_address@gmail.com:My Google App Password

You do not need to worry about the spaces in the app password. Then hash map the password file:

sudo postmap /etc/postfix/sysl_passwd

After this command ran, you will see a sasl_passwd.db file in /etc/postfix. Permission son this file should be root:root.

Configure Postfix to use the Gmail relay host

Add the following lines to the Postfix main.cf file:

sudo nano /etc/postfix/main.cf
myhostname = freepbx.my.domain
relayhost = [smtp.gmail.com]:587

#Enable SASL authentication
smtp_sasl_auth_enable = yes

#Disallow methods that allow anonymous authentication
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt

# Location of sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

Now restart your postfix service:

nano systemctl restart postfix

Test your Postfix installation

echo "This is a test email" | mail -s "Test mail" destination@email.address

Optional: force Postfix to rewrite your address

Sometimes messages are rejected if the from user and the sending user don’t match up. If this happens, you have to add the following lines to the generic configuration file:

sudo nano /etc/postfix/generix
root my.sending@email.address 
root@localhost my.sending@email.address 
root@localhost.localdomain my.sending@email.address 
root@freepbx my.sending@email.address 
root@freepbx.localdomain my.sending@email.address 
asterisk my.sending@email.address 
asterisk@localhost my.sending@email.address 
asterisk@localhost.localdomain my.sending@email.address 
asterisk@freepbx my.sending@email.address 
asterisk@freepbx.localdomain my.sending@email.address
vm@asterisk my.sending@email.address

Hash map the generic file:

postmap /etc/postfix/generic

You have to add the following line to thew main.cf file:

smtp_generic_maps = hash:/etc/postfix/generic

Don’t forget to restart the Postfix service.

Test your email from FreePBX

Go to the Admin menu, User Manager submenu, select the user you want to send an email to and hit the Send Email button.

Admin / User Manager

Don’t forget to associate an email address to the user.

Leave a Reply