Thought I would share this as I have been fighting it for a few days. I was able to finally get postfix setup with office365 so that sendmail would work. This is mostly a copy/paste of this site so I don't claim to be the originator but I had to insure saslauthd was installed and running before it worked. That's the part that was not in the original write-up.
Step 1: Install Required Packages
First, update your package list and install the necessary mail utilities:
Code:
apt-get update
apt-get install postfix mailutils sasl2-bin libsasl2-modules
Step 2: Configure Postfix
Edit the main Postfix configuration file:
Code:
nano /etc/postfix/main.cf
Code:
relayhost = [smtp.office365.com]:587
mynetworks = 127.0.0.0/8
inet_interfaces = loopback-only
inet_protocols = ipv4
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
CTRL+X
, then Y
, then Enter
.Step 3: Configure Authentication (sasl_passwd)
Create the authentication file:
Code:
nano /etc/postfix/sasl_passwd
username@yourdomain.com
and password
with your Office365 credentials:
Code:
[smtp.office365.com]:587 username@yourdomain.com:password
Code:
chown root:root /etc/postfix/sasl_passwd
chmod 0600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
Step 4: Configure Generic Mapping
Create thegeneric
file:
Code:
nano /etc/postfix/generic
Code:
root@localdomain username@yourdomain.com
@localdomain username@yourdomain.com
Set the correct permissions and hash the file:
Code:
chown root:root /etc/postfix/generic
chmod 0600 /etc/postfix/generic
postmap /etc/postfix/generic
Step 5: Ensure saslauthd is Installed and Running
Check ifsaslauthd
is installed and running:
Code:
systemctl status saslauthd
Code:
systemctl start saslauthd
systemctl enable saslauthd
Step 6: Test the Configuration
Restart Postfix:
Code:
systemctl restart postfix
Code:
echo "This is a test email" | mail -s "Relay Test Email" recipient@example.com -a "From: username@yourdomain.com"
Step 7: Troubleshooting
If you do not receive the test email, check the logs:tail -f /var/log/mail.log
If sending to another user in the same domain
yourdomain.com
fails, check the mydestination
setting in main.cf
and remove yourdomain.com
if present.