You need a reliable way for your VoIP-based PBX to send email to you and your users when voicemail messages arrive and when something goes wrong on your server. For Incredible PBX® platforms at least, we thought we had solved that with our Gmail Smarthost solution. Unfortunately, Google keeps moving the goalposts, and on May 30, 2022 it announced it would end support for "Less Secure Apps". After watching Google blow up its apps one after another over the years, you would think we would have learned.
Why Do You Need a RelayHost? Many Internet Service Providers (ISPs) block downstream mail servers from sending email in order to reduce spam. If you have a PBX sitting behind a Comcast cable modem and you don't have a business account, that would be you.
What Is a RelayHost? A RelayHost is an intermediary mail provider that handles the last-mile delivery of your server's outbound email without you having to worry about the complexities of setting up and properly configuring an SMTP gateway. Instead, your server forwards your outbound email messages to the smart host using your credentials, leaving the rest of the delivery job to the RelayHost.
Choosing a RelayHost. Luckily for all of us, there are many RelayHost providers to choose from. Most offer a free tier with 100 or more emails per day. For most PBXs, that is more than enough without spending a penny. If your server sends more than 100 emails a day, commercial service tiers are available from the same providers. Here are some favorites recommended by our users: Twilio's SendGrid , Mailjet , SendInBlue. If you can't get any of the other free offerings to work, we would prefer that you use our service only as a last resort. To get started, I will show you how to set up Twilio's SendGrid as your RelayHost.
Configuring a RelayHost with Incredible PBX. There is good news and bad news. While all of these solutions offer a free tier, the setup process with some of these services can be a bit tricky. I will guide you through the setup steps. To simplify the setup procedure for newcomers using SendMail as an SMTP Smart Host, we will first switch your PBX to Postfix. Here is a quick list of the tasks:
- Move Your PBX from SendMail to Postfix
- Get an Account with a SmartHost Provider
- Configure Postfix Email Relay Using the SmartHost Provider
- Test Outbound Mail
Moving Incredible PBX 2022 to Postfix. Our new Incredible PBX 2022 build for Rocky 8 comes with both SendMail and Postfix preinstalled. So switching gears is easy. Here are the commands:
systemctl stop sendmail
systemctl disable sendmail
systemctl start postfix
systemctl enable postfix
sed -i 's|-c sendmail|-c postfix|' /usr/local/sbin/pbxstatus
sed -i 's|SendMail| Postfix|' /usr/local/sbin/pbxstatus
systemctl status postfix
Moving Incredible PBX 2021 to Postfix. By default, Incredible PBX 2021 servers do not include Postfix. Here are the steps to install Postfix and remove SendMail. These steps also apply to all Incredible PBX versions on the Raspbian platform.
apt-get update
apt-get install postfix sasl2-bin -y
# choose No Configuration option when prompted in:
# dpkg-reconfigure postfix
systemctl stop sendmail
systemctl disable sendmail
systemctl start postfix
systemctl enable postfix
sed -i 's|-c sendmail|-c postfix|' /usr/local/sbin/pbxstatus
echo "incrediblepbx.com" > /etc/mailname
sed -i 's|SendMail| Postfix|' /usr/local/sbin/pbxstatus
systemctl status postfix
Creating a Free SendGrid Account. Start by going to the SendGrid Start for Free link . Enter your Email Address and a 16-character password of your choice. Accept the Terms of Service and click Create Account. Fill in the Personal Information and click Get Started. Create a Single Sender Identity. Confirm that the verification email was received. If you like, you can skip enabling Two-Factor Authentication. Next, open the Email API tab and click Integration Guide. Select SMTP Relay and create an APIKEY. Copy the generated APIKEY to a safe place. It cannot be decrypted again!
Now edit /etc/postfix/main.cf and add the following entries to the bottom of the file:
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587
Then create /etc/postfix/sasl_passwd and enter the following, replacing YOUR-APIKEY with your actual key from above:
[smtp.sendgrid.net]:587 apikey:YOUR-APIKEY
Finish the setup by issuing the following commands:
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
systemctl restart postfix
systemctl status postfix
IMPORTANT NOTE: With SendGrid, the email address you entered for your Single Sender Identity must match the FROM: address on every outbound email message sent from your server. We will need to set the FROM: address in FreePBX so that any voicemail email can be sent successfully. Also, if you send email from the command line, the syntax must match what was entered as your Sender Identity email address, with sender@yourdomain.com as shown here.
echo "test" | mail -r sender@yourdomain.com -s testmessage recipient@somedomain.com
Gmail recipients at least may see the following along with messages from your PBX until they click Looks Safe :
Finally, make sure you set the FROM address for outbound voicemail messages in the FreePBX GUI. Log in as admin and enter your Sender Identity Email Address in the Server Email field under Settings -> Voicemail Admin -> Settings -> Email Config.
You can check for errors by examining the Postfix mail log: tail /var/log/mail.log .
UPDATE: Setup scripts for Debian 10 and Rocky 8 can be downloaded here.