Following https://stackoverflow.com/a/62543536/6009580 I've tried sending mails from a docker container using the SMTP server of the host.
What is working:
[HOST]$ echo "Test mail." | mail -s "message" my@mail.com # works
[HOST]$ sudo docker run --net=host -it python
[python-container] >>> import smtplib
[python-container] >>> s = smtplib.SMTP('localhost')
[python-container] >>> s.sendmail("from@mail.com",["my@mail.com"],"message") # works
What is not working:
[HOST]$ sudo docker run -it python
[python-container] >>> import smtplib
[python-container] >>> s = smtplib.SMTP('host.docker.internal')
socket.gaierror: [Errno -2] Name or service not known
Even if I start the container with
[HOST]$ sudo docker run --add-host=host.docker.internal:host-gateway -it python
[python-container] >>> import smtplib
[python-container] >>> s = smtplib.SMTP('host.docker.internal')
ConnectionRefusedError: [Errno 111] Connection refused
Any help is appreciated
System:
- Rocky Linux 8.7
- Docker 20.10.22