Project

General

Profile

Actions

CdmServer in docker instance sending e-mails » History » Revision 3

« Previous | Revision 3/15 (diff) | Next »
Belen Escobari, 04/18/2023 10:28 AM


CdmServer in docker instance sending e-mails

Problem:

For the self registration in phycobank it is necessary that the cdmServer is able to send emails. This works fine for the cdmServer running on the host system, but fails when the cdmServer is running in a docker instance.

The mail is sent with org.springframework.mail.javamail.JavaMailSender and the host is defined as localhost, this does not work within docker because the MTA (exim4) runs on the host machine.

Ideas:

First we have to install ssmtp on docker-container, this is already done with inside Dockerfile:

RUN apt-get update && apt-get install -y ssmtp && rm -rf /var/lib/apt/lists/*

COPY ssmtp.conf /etc/ssmtp/ssmtp.conf

To analyse the ip configuration also iproute2 is installed:

RUN apt-get update && apt-get install -y iproute2 && rm -rf /var/lib/apt/lists/*

Some urls to find ideas how to fix the problem:

https://gehrcke.de/2014/07/discourse-docker-container-send-mail-through-exim/
https://stackoverflow.com/questions/26215021/configure-sendmail-inside-a-docker-container/30021595#30021595 (using postfix instead of exim4)

How to connect from inside the docker instance to localhost:
https://www.howtogeek.com/devops/how-to-connect-to-localhost-within-a-docker-container/
Configure firewall to allow the docker container connecting to host MTA
https://docs.docker.com/network/iptables/
https://serverfault.com/questions/705192/iptables-rule-set-so-that-a-docker-container-can-access-a-service-on-a-host-ip

The docker container can be started with different network modes, for us it is the bridge mode, this means between docker container and host system there is a bridge with different IP adresses on container side (172.17.0.1) and host side (172.17.0.1).
So we need to configure exim4 to listen also on 172.17.0.1 and ssmtp to send the mails to 172.17.0.2 (mailhub).

Updated by Belen Escobari about 1 year ago · 3 revisions