0

I'm configuring a new Ubuntu server (18.04 LTS) to act as a mail relay for internal hosts to send mail out, for things like notification emails when a device has an issue. We use Office 365, so this allows us to funnel these kinds of messages from equipment and software in-house to our mailboxes. My organization has had this set up very simply with Postfix for a number of years. Unfortunately, the employee who set it up is long gone, and I can't find any documentation as to the specifics. However, based on some information I've found, it doesn't appear that the configuration needs to be that complex. I have installed Postfix on the new system, and tried to configure it to match the existing config as much as possible. Here's my /etc/postfix/main.cf file, with changes to anonymize:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated     defer_unauth_destination
myhostname = myservername.domain.edu
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = myservername.domain.edu, localhost.domain.edu, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
message_size_limit = 10240000
permit_mynetworks = yes
mynetworks = 172.16.4.0/24, 172.16.5.0/24, 172.16.246.0/24, 192.168.90.0/24, 192.168.1.0/24, ###.###.103.0/24, ###.###.104.0/24, ###.###.106.0/24, ###.###.250.0/24, 10.19.64.0/27, 10.19.66.0/27, 10.19.68.0/27

I can get out to the internet from this new server, I can ping resources on the internet, etc. but it isn't sending mail. I keep seeing log entries about the messages being deferred, and connections timing out. Here's the last 30 lines of my /var/log/mail.log file, so you can see the kinds of messages I'm seeing. Again, I've anonymized the contents:

user@myservername:~$ tail -30 /var/log/mail.log
May 29 14:23:49 myservername postfix/smtp[3351]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:24:19 myservername postfix/smtp[3349]: connect to subdomain.domain.edu[###.###.104.118]:25: Connection timed out
May 29 14:24:19 myservername postfix/smtp[3350]: connect to mxa-00246402.gslb.pphosted.com[148.163.147.197]:25: Connection timed out
May 29 14:24:19 myservername postfix/smtp[3351]: connect to subdomain.domain.edu[###.###.104.154]:25: Connection timed out
May 29 14:24:19 myservername postfix/smtp[3351]: connect to subdomain.domain.edu[###.###.104.57]:25: Connection refused
May 29 14:24:19 myservername postfix/smtp[3351]: connect to subdomain.domain.edu[###.###.103.6]:25: Connection refused
May 29 14:24:19 myservername postfix/smtp[3351]: connect to subdomain.domain.edu[###.###.250.72]:25: Connection refused
May 29 14:24:49 myservername postfix/smtp[3350]: connect to mxb-00246402.gslb.pphosted.com[148.163.143.147]:25: Connection timed out
May 29 14:24:49 myservername postfix/smtp[3349]: connect to subdomain.domain.edu[###.###.103.43]:25: Connection timed out
May 29 14:24:49 myservername postfix/bounce[3357]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:24:49 myservername postfix/smtp[3351]: connect to subdomain.domain.edu[###.###.103.43]:25: Connection timed out
May 29 14:24:49 myservername postfix/bounce[3358]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:24:49 myservername postfix/smtp[3350]: 35A96120180: to=<apc@domain.edu>, relay=none, delay=631, delays=571/0.03/60/0, dsn=4.4.1, status=deferred (connect to mxb-00246402.gslb.pphosted.com[148.163.143.147]:25: Connection timed out)
May 29 14:24:49 myservername postfix/smtp[3351]: 4047E12083C: to=<username@subdomain.domain.edu>, relay=none, delay=431116, delays=431056/0.04/60/0, dsn=4.4.1, status=deferred (connect to subdomain.domain.edu[###.###.103.43]:25: Connection timed out)
May 29 14:25:19 myservername postfix/smtp[3349]: connect to subdomain.domain.edu[###.###.104.154]:25: Connection timed out
May 29 14:25:19 myservername postfix/smtp[3349]: 68665120733: to=<username@subdomain.domain.edu>, relay=none, delay=434852, delays=434761/0.06/90/0, dsn=4.4.1, status=deferred (connect to subdomain.domain.edu[###.###.104.154]:25: Connection timed out)
May 29 14:25:19 myservername postfix/qmgr[1688]: 68665120733: from=<apc@domain.edu>, status=expired, returned to sender
May 29 14:25:19 myservername postfix/cleanup[3365]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:25:19 myservername postfix/cleanup[3365]: CE1B8124492: message-id=<20180529192519.CE1B8124492@myservername.domain.edu>
May 29 14:25:19 myservername postfix/bounce[3357]: 68665120733: sender non-delivery notification: CE1B8124492
May 29 14:25:19 myservername postfix/qmgr[1688]: CE1B8124492: from=<>, size=2844, nrcpt=1 (queue active)
May 29 14:25:19 myservername postfix/qmgr[1688]: 68665120733: removed
May 29 14:25:49 myservername postfix/smtp[3350]: connect to mxa-00246402.gslb.pphosted.com[148.163.147.197]:25: Connection timed out
May 29 14:26:19 myservername postfix/smtp[3350]: connect to mxb-00246402.gslb.pphosted.com[148.163.147.197]:25: Connection timed out
May 29 14:26:19 myservername postfix/smtp[3350]: CE1B8124492: to=<apc@domain.edu>, relay=none, delay=60, delays=0.03/0/60/0, dsn=4.4.1, status=deferred (connect to mxb-00246402.gslb.pphosted.com[148.163.147.197]:25: Connection timed out)
May 29 14:28:49 myservername postfix/qmgr[1688]: 8F7B51200D6: from=<>, size=2838, nrcpt=1 (queue active)
May 29 14:28:49 myservername postfix/trivial-rewrite[3378]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:28:49 myservername postfix/qmgr[1688]: 92033120E39: from=<>, size=2836, nrcpt=1 (queue active)
May 29 14:28:49 myservername postfix/smtp[3379]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
May 29 14:28:49 myservername postfix/smtp[3380]: warning: /etc/postfix/main.cf, line 49: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

There's no firewall configured or running on the host itself, and based on my conversations with the network engineer, there should be nothing blocking this traffic. However, from the existing server, I can telnet to the Office 365 mail server name listed in the MX record for my organization, on port 25, and get a response, throw a 'helo' at it, etc. I cannot do the same from this new server. My network engineer is confident that there's nothing on the firewall that would be blocking the outgoing traffic, and while he's been trying to help me troubleshoot this, he hasn't seen anything that would indicate what's causing it. I'm not sure what else I could be missing. Any help would be greatly appreciated.

1 Answer 1

0

In order to configure a SMTP-Relay you have to define a relayhost along with some sasl authentication items.

Would you like to add these configuration items to the end of your main.cf?

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password
relayhost = your.office365.relayhost
smtp_tls_security_level = may

Obviously you have to change "your.office365.relayhost" by the real hostname (which should be [smtp.office365.com]:587 according to this link: https://secopsmonkey.com/mail-relaying-postfix-through-office-365.html

The file sasl_password is also explained in the linked tutorial, it should look something like

[smtp.office365.com]:587 user@domain.tld:soopersekretPassvv0rd

and you will have to postmap it with postmap hash:/etc/postfix/sasl_passwd. After that you'll have to restart postfix with systemctl restart postfix.service.

I'm not familiar with Office 365 but for relaying via MS Exchange Servers it's quite usual that you have to try different ports.

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.