Search code examples
javadockerjakarta-mailpostfix-mtadovecot

JavaMail fails to send email from docker container


I just deployed some Java code to production(its a Java web app deployed in Tomcat) and I noticed that the module responsible for sending Email started to fail.

This was not the case when the code was running on my local system. I could at least send to Yahoo! mail, Google mail and mail boxes on my local server.

When sent from my local system, the logs on my server (/var/log/maillog)

show:

Jun  8 08:37:22 folo-folo postfix/smtps/smtpd[31137]: connect from unknown[41.220.75.164]
Jun  8 08:37:25 folo-folo postfix/smtps/smtpd[31137]: 67EA680EA480: client=unknown[41.220.75.164], sasl_method=LOGIN, [email protected]
Jun  8 08:37:26 folo-folo postfix/cleanup[31216]: 67EA680EA480: message-id=<1177096266.0.1559979567305.JavaMail.gbemirojiboye@Gbemiros-MacBook-Pro.local>
Jun  8 08:37:26 folo-folo postfix/qmgr[6945]: 67EA680EA480: from=<[email protected]>, size=530, nrcpt=2 (queue active)
Jun  8 08:37:26 folo-folo postfix/smtps/smtpd[31137]: disconnect from unknown[41.220.75.164]
Jun  8 08:37:26 folo-folo postfix/smtp[31217]: 67EA680EA480: to=<[email protected]>, relay=gmail-smtp-in.l.google.com[108.177.15.26]:25, delay=1.7, delays=1.1/0.02/0.3/0.24, dsn=2.0.0, status=sent (250 2.0.0 OK  1559979574 e2si3106225wrj.113 - gsmtp)
Jun  8 08:37:28 folo-folo postfix/smtp[31218]: 67EA680EA480: to=<[email protected]>, relay=mta7.am0.yahoodns.net[98.137.159.24]:25, delay=3.4, delays=1.1/0.03/1.5/0.79, dsn=2.0.0, status=sent (250 ok dirdel)
Jun  8 08:37:28 folo-folo postfix/qmgr[6945]: 67EA680EA480: removed

This message ends up being sent.

But when sent from the same app deployed in tomcat inside a docker container, the logs become:

Jun  8 08:34:27 folo-folo postfix/smtps/smtpd[30255]: connect from unknown[172.18.0.6]
Jun  8 08:34:29 folo-folo postfix/smtps/smtpd[30255]: warning: unknown[172.18.0.6]: SASL LOGIN authentication failed: **UGFzc3dvcmQ6**
Jun  8 08:34:29 folo-folo postfix/smtps/smtpd[30255]: lost connection after AUTH from unknown[172.18.0.6]
Jun  8 08:34:29 folo-folo postfix/smtps/smtpd[30255]: disconnect from unknown[172.18.0.6]

This message IS NEVER sent.

I can see from the server logs on the host that the Docker container is able to make the mail request, but for some reason, authentication fails.

I can hazard a guess that it would work if I made the request instead to an api on the host container and have it send the email. But that would be very inconvenient for my design.

How do I solve this problem?

I should mention that the problem here looks suspiciously like the one posted here


Solution

  • This was my error.

    My credentials were mixed up and that was what caused the errors in making the requests from Docker.

    Correcting the credentials made the errors go away.