I'm running Postfix 3.4.8 on Debian 10 (buster) in Docker 19.03.5. Postfix is configured as a smarthost. It relays emails to the SMTP server of our ISP.
If I configure the relayhost
setting with the domain name of the SMTP server, in my case [mail.level27.be]:587
, then I get this error when sending mail:
Host or domain name not found. Name service error for name=mail.level27.be type=A: Host not found, try again
If I configure the relayhost
setting with the IP of the SMTP server, in my case [185.3.216.85]:587
, it works!
I guess it's a DNS issue. How can I make it work with the domain name in stead of the IP?
The Docker image is build with this command:
docker build --pull -t mypostfix .
Here is the Dockerfile:
FROM debian:10
EXPOSE 25
RUN apt-get update
RUN apt-get -y install libsasl2-modules postfix
RUN postconf -X 'mynetworks' \
&& postconf -e 'mynetworks_style = subnet' \
&& postconf -X 'mydestination' \
&& postconf -e 'remote_header_rewrite_domain =' \
&& postconf -e 'inet_protocols = ipv4' \
&& postconf -e 'relayhost = [mail.level27.be]:587' \
&& postconf -e 'smtp_use_tls = yes' \
&& postconf -e 'smtp_sasl_auth_enable = yes' \
&& postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd' \
&& postconf -e 'smtp_sasl_security_options = noanonymous' \
&& postconf -e 'maillog_file = /dev/stdout' \
&& echo "mail.level27.be username:password" > /etc/postfix/sasl_passwd \
&& chown root:root /etc/postfix/sasl_passwd \
&& chmod 600 /etc/postfix/sasl_passwd \
&& postmap /etc/postfix/sasl_passwd
CMD postfix start-fg
The Docker container is started with this command:
docker run --rm -d -p 25:25 mypostfix
The email is sent on the Docker host with this curl
command:
echo "This is some mail content." > /tmp/email.txt
curl --url 'smtp://localhost:25' --mail-from 'xxx.yyy@zzz.be' --mail-rcpt 'xxx.yyy@zzz.be' --upload-file /tmp/email.txt
The error can be seen by running postqueue -p
in the container:
root@mypostfix:/# postqueue -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
DBB26A05886 256 Wed Feb 19 14:45:42 xxx.yyy@zzz.be
(Host or domain name not found. Name service error for name=mail.level27.be type=A: Host not found, try again)
xxx.yyy@zzz.be
-- 0 Kbytes in 1 Request.
Best Answer
Looks like you have issue with DNS resolving inside container. There is good blog post, where described your issue, check it out.