loganmarchione / docker-postfixrelay

Runs Postfix (as a relay) in Docker
https://hub.docker.com/r/loganmarchione/docker-postfixrelay
MIT License
28 stars 5 forks source link

Cant connect to Office365 SMTP with no password #35

Closed DrunkMunki closed 9 months ago

DrunkMunki commented 9 months ago

Hello, We have several internal systems and want to setup a docker SMTP to relay emails to Office365. Your ENV Variables indicate RELAY_USER and RELAY_PASS arent required. We are using IP based authentication as we dont need a mailbox for each system sending emails...

When i attempt to relay mail to smtp.office365.com on port 587 i get the errors:

im assuming by "SASL authentication failure: All-whitespace username" its passing the username through?

Jan 25 11:49:38 dbeb7b45e2b9 postfix/qmgr[436]: CB7251661E1: from=<docker@domainreplaced.com>, size=503, nrcpt=1 (queue active)

Jan 25 11:49:39 dbeb7b45e2b9 postfix/smtp[512]: Trusted TLS connection established to smtp.office365.com[52.98.143.98]:587: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature RSA-PSS (2048 bits) server-digest SHA256

Jan 25 11:49:39 dbeb7b45e2b9 postfix/smtp[512]: warning: SASL authentication failure: All-whitespace username.

-- repeated log entries ---

Jan 25 11:49:41 dbeb7b45e2b9 postfix/smtp[512]: CB7251661E1: to=<testemail@domainreplaced.com>, relay=smtp.office365.com[52.98.140.2]:587, delay=2.5, delays=0.02/0.12/2.3/0, dsn=4.7.0, status=deferred (SASL authentication failed; cannot authenticate to server smtp.office365.com[52.98.140.2]: generic failure)

any ideas?

loganmarchione commented 9 months ago

Sorry for the delay...

Hmmmm, nice catch here. Guess I never considered IP-based auth without RELAY_USER and RELAY_PASS.

The way it works now, I echo them out, but if they're blank, it echos the colon : which is probably being read as a blank username before and a blank password after.

https://github.com/loganmarchione/docker-postfixrelay/blob/378a1d3be5fc2cdefc0ada0f56195c24c410ea8f/entrypoint.sh#L77

Thoughts on an if statement? If the RELAY_USER and RELAY_PASS are blank, it won't echo them.

if [ -n "$RELAY_USER" ] && [ -n "$RELAY_PASS" ]; then
  echo "[$RELAY_HOST]:$RELAY_PORT   $RELAY_USER:$RELAY_PASS" > /etc/postfix/sasl_passwd
else
  echo "[$RELAY_HOST]:$RELAY_PORT" > /etc/postfix/sasl_passwd
fi
DrunkMunki commented 9 months ago

I dont think any change is needed. i tested with your example and was able to receive the email, i believe the issue was mine as i specified smtp.office365.com when it should have been my-domain-name.mail.protection.outlook.com on port 25. I rolled back to your latest image with the my-domain-name.mail.protection.outlook.com as my SMTP address and confirmed it was working.