Gmail won't send emails to Postfix over port 587

56 views Asked by At

I have a postfix email server (mx) in a docker container on a host. My MX only receives emails (SMTPD). My goal is to receive emails from gmail on port 587 so that TLS is always enforced. However, I can only receive emails from gmail if port 25 is open. As an independent way to check encrypted SMTPD (ESMTPD), I am using openssl s_client to send emails as well.

Here are my inbound firewall rules on the host when both ports 25 and 587 are open. enter image description here

Here is my docker-compose.yml when both ports 25 and 587 are open:

services:
  mailserver:
    # More information about the mail-server ports:
    # https://docker-mailserver.github.io/docker-mailserver/edge/config/security/understanding-the-ports/
    # To avoid conflicts with yaml base-60 float, DO NOT remove the quotation marks.
    ports:
      - '25:25' # SMTP (temporarily opened for troubleshooting)
      - '587:587'  # ESMTP (explicit TLS => STARTTLS)

Here is my postfix/main.cf.

# 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/letsencrypt/live/mail.example.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem
smtpd_tls_security_level = encrypt

smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level=may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mail
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = mail.example.com, example.com, localhost.example.com, localhost.localdomain, localhost
relayhost = 
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
maillog_file = /var/log/mail.log
myorigin = example.com
home_mailbox = Maildir/

Here is my Here is my postfix/master.cf.

# Postfix master process configuration file.  For details on the format
# of the file, see the master(5) manual page (command: "man 5 master" or
# on-line: http://www.postfix.org/master.5.html).
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (no)    (never) (100)
# ==========================================================================
#smtp      inet  n       -       y       -       1       postscreen
#smtpd     pass  -       -       y       -       -       smtpd
#dnsblog   unix  -       -       y       -       0       dnsblog
#tlsproxy  unix  -       -       y       -       0       tlsproxy
#submission inet n       -       y       -       -       smtpd
#  -o syslog_name=postfix/submission
#  -o smtpd_tls_security_level=encrypt
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_tls_auth_only=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#smtps     inet  n       -       y       -       -       smtpd
#  -o syslog_name=postfix/smtps
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=
#  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#628       inet  n       -       y       -       -       qmqpd
smtp       inet  n       -       n       -       -       smtpd
pickup     unix  n       -       n       60      1       pickup
cleanup    unix  n       -       n       -       0       cleanup
#qmgr     unix  n       -       n       300     1       oqmgr
qmgr       unix  n       -       n       300     1       qmgr
tlsmgr     unix  -       -       n       1000?   1       tlsmgr
rewrite    unix  -       -       n       -       -       trivial-rewrite
bounce     unix  -       -       n       -       0       bounce
defer      unix  -       -       n       -       0       bounce
trace      unix  -       -       n       -       0       bounce
verify     unix  -       -       n       -       1       verify
flush      unix  n       -       n       1000?   0       flush
proxymap   unix  -       -       n       -       -       proxymap
proxywrite unix  -       -       n       -       1       proxymap
smtp       unix  -       -       n       -       -       smtp
#       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
relay      unix  -       -       n       -       -       smtp
    -o syslog_name=postfix/$service_name
showq      unix  n       -       n       -       -       showq
error      unix  -       -       n       -       -       error
retry      unix  -       -       n       -       -       error
discard    unix  -       -       n       -       -       discard
local      unix  -       n       n       -       -       local
virtual    unix  -       n       n       -       -       virtual
lmtp       unix  -       -       n       -       -       lmtp
anvil      unix  -       -       n       -       1       anvil
scache     unix  -       -       n       -       1       scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent.  See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
postlog    unix-dgram n  -       n       -       1       postlogd
#
# ====================================================================
#
# Recent Cyrus versions can use the existing "lmtp" master.cf entry.
#
# Specify in cyrus.conf:
#   lmtp    cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4
#
# Specify in main.cf one or more of the following:
#  mailbox_transport = lmtp:inet:localhost
#  virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus     unix  -       n       n       -       -       pipe
#  user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix  -       n       n       -       -       pipe
#  flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
maildrop   unix  -       n       n       -       -       pipe flags=DRhu
    user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# Other external delivery methods.
#
uucp       unix  -       n       n       -       -       pipe flags=Fqhu
    user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
ifmail     unix  -       n       n       -       -       pipe flags=F user=ftn
    argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp      unix  -       n       n       -       -       pipe flags=Fq.
    user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix - n       n       -       2       pipe flags=R
    user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop}
    ${user} ${extension}

mailman    unix  -       n       n       -       -       pipe flags=FR
    user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py ${nexthop}
    ${user}
submission inet  n       -       n       -       -       smtpd
    -o syslog_name=postfix/submission
    -o smtpd_tls_security_level=encrypt

Using openssl s_client, I can receive an email on my MX when only port 587 is open.

kfike@pop-os:~$ openssl s_client -starttls smtp -ign_eof -crlf -connect mail.example.com:587
CONNECTED(00000003)
read R BLOCK
ehlo mail.example.com
250-mail
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
MAIL FROM: <[email protected]>
250 2.1.0 Ok
RCPT TO: <[email protected]>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Subject: 24022801 openssl 587
24022801 openssl 587
.
250 2.0.0 Ok: queued as 484164047A
quit
221 2.0.0 Bye
closed

When I open port 25 on the host and the container, I receive all the emails I had previously sent when port 25 was closed:

sage-mailserver  | Feb 28 03:38:18 prod postfix/smtpd[225]: connect from mail-io1-f47.google.com[209.85.166.47]
sage-mailserver  | Feb 28 03:38:18 prod postfix/smtpd[225]: D5AED40485: client=mail-io1-f47.google.com[209.85.166.47]
sage-mailserver  | Feb 28 03:38:18 prod postfix/cleanup[266]: D5AED40485: message-id=<CAG3XwjSVnRON0o7ku58uTCPkFxywounaJYbPfUZ_S30MNQ8NRQ@mail.gmail.com>
sage-mailserver  | Feb 28 03:38:18 prod postfix/qmgr[175]: D5AED40485: from=<[email protected]>, size=2923, nrcpt=1 (queue active)
sage-mailserver  | Feb 28 03:38:18 prod postfix/local[267]: D5AED40485: to=<[email protected]>, relay=local, delay=0.02, delays=0.01/0.01/0/0, dsn=2.0.0, status=sent (delivered to maildir)
sage-mailserver  | Feb 28 03:38:18 prod postfix/qmgr[175]: D5AED40485: removed
sage-mailserver  | Feb 28 03:38:18 prod postfix/smtpd[225]: disconnect from mail-io1-f47.google.com[209.85.166.47] ehlo=2 starttls=1 mail=1 rcpt=1 bdat=1 quit=1 commands=7
sage-mailserver  | Feb 28 03:38:53 prod postfix/smtpd[225]: connect from mail-qt1-f176.google.com[209.85.160.176]
sage-mailserver  | Feb 28 03:38:53 prod postfix/smtpd[225]: E1E1640485: client=mail-qt1-f176.google.com[209.85.160.176]
sage-mailserver  | Feb 28 03:38:53 prod postfix/cleanup[266]: E1E1640485: message-id=<CAG3XwjRC0NyH0qej3EhGTz8YvhbiBLUTVB-NF6ZaaUAwcwmqXg@mail.gmail.com>
sage-mailserver  | Feb 28 03:38:53 prod postfix/qmgr[175]: E1E1640485: from=<[email protected]>, size=2917, nrcpt=1 (queue active)
sage-mailserver  | Feb 28 03:38:53 prod postfix/local[267]: E1E1640485: to=<[email protected]>, relay=local, delay=0.02, delays=0.01/0/0/0.01, dsn=2.0.0, status=sent (delivered to maildir)
sage-mailserver  | Feb 28 03:38:53 prod postfix/qmgr[175]: E1E1640485: removed
sage-mailserver  | Feb 28 03:38:53 prod postfix/smtpd[225]: disconnect from mail-qt1-f176.google.com[209.85.160.176] ehlo=2 starttls=1 mail=1 rcpt=1 bdat=1 quit=1 commands=7
sage-mailserver  | Feb 28 03:40:23 prod postfix/smtpd[225]: connect from mail-qk1-f177.google.com[209.85.222.177]
sage-mailserver  | Feb 28 03:40:23 prod postfix/smtpd[225]: E8BB740485: client=mail-qk1-f177.google.com[209.85.222.177]
sage-mailserver  | Feb 28 03:40:23 prod postfix/cleanup[266]: E8BB740485: message-id=<CAG3XwjTxJwQQaCWXjzCD5jg73=6+jEJNWXXj7oF1AqbTnN81ag@mail.gmail.com>
sage-mailserver  | Feb 28 03:40:23 prod postfix/qmgr[175]: E8BB740485: from=<[email protected]>, size=2920, nrcpt=1 (queue active)
sage-mailserver  | Feb 28 03:40:23 prod postfix/local[267]: E8BB740485: to=<[email protected]>, relay=local, delay=0.01, delays=0.01/0/0/0, dsn=2.0.0, status=sent (delivered to maildir)

In summary: | Open Port(s) | Client | Email received? | | ------------ | ------ | -------------- | | 25 and 587 | openssl s_client | Yes | | 25 and 587 | gmail | Yes | | 587 | openssl s_client | Yes | | 587 | gmail | No |

Any ideas as why I can't receive emails from gmail when only port 587 is open and not port 25? Thanks so much for any insights!

0

There are 0 answers