SMTP relay using office365 for FreePBX or rhel based distros

FreePBX use a paid module called System Admin PRO for easily config smtp server settings, but if you cant pay here is a example of manual config using a office365 email account

This process can be useful for sending EMAILS using office365 account through Centos 7 server, or based like SANGOMA Linux used by FreePBX

Install packages

[root@localhost ~]# yum install postfix cyrus-sasl-plain mailx

Edit config file of postfix (vim or prefered text editor)

root@localhost ~]# vim /etc/postfix/

Append the configuration

relayhost = []:587
mynetworks =
inet_interfaces = loopback-only
smtp_use_tls = yes
smtp_always_send_ehlo = yes
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
smtp_generic_maps = hash:/etc/postfix/generic
#smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Credentials for sending account

[root@localhost ~]# vim /etc/postfix/sasl_passwd



Save and exit from text editor

Exec postmap for create lookup table:

[root@localhost ~]# postmap /etc/postfix/sasl_passwd

Change permissions of file

[root@localhost ~]# chown root:postfix /etc/postfix/sasl_passwd
[root@localhost ~]# chmod 640 /etc/postfix/sasl_passwd

Configuration of generic file in order to be able to send emails as a valid user (required for Office365)

[root@localhost ~]# vim /etc/postfix/generic

Append these line and EDIT USER AND DOMAIN:


Save the file and exit from text editor

Change file permissions for security reasons

[root@localhost ~]# chown root:root /etc/postfix/generic
[root@localhost ~]# chmod 0600 /etc/postfix/generic
[root@localhost ~]# postmap /etc/postfix/generic

Change alias root to email address

[root@localhost ~]# vim /etc/aliases

Make changes like (EDIT USER AND DOMAIN)

mailer-daemon: postmaster
postmaster: root

Save and exit from text editor

Rebuild the data base for the mail aliases file

[root@localhost ~]# newaliases

Restart postfix service

[root@localhost ~]# systemctl restart postfix

Test config sending a email (EDIT SENDER EMAIL AND RECIPIENT)

echo "This is the body of the email"| mail -r "Sender-Display-Name<>" -s "This is the subject(E-Mail from SMTP Relay) line"

You can debug the process monitoring /var/log/maillog file

Oct 31 15:01:24 freepbx postfix/smtp[20049]: 0FD4EA2329F: to=<>,[]:587, delay=3.1, delays=0.14/0.01/2.2/0.83, dsn=2.0.0, status=sent (250 2.0.0 OK <> [])
Oct 31 15:01:24 freepbx postfix/qmgr[8181]: 0FD4EA2329F: removed

When we send an email display name will be root let’s modify root user’s description
Edit “My Name”

[root@localhost ~]# usermod -c "My Name" root

Now sender name has been changed to the actual user name.