在Docker容器中通过curl(smpt)发送电子邮件

我可以在本地使用以下脚本接收电子邮件

rtmp_url="smtp://smtp.xxx.com:25" rtmp_from="noreply@xxx.com" rtmp_to="receiver-email@xxx.com" file_upload="mail.txt" echo "From: $rtmp_from To: $rtmp_to Subject: example of mail Cc: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=\"MULTIPART-MIXED-BOUNDARY\" --MULTIPART-MIXED-BOUNDARY Content-Type: multipart/alternative; boundary=\"MULTIPART-ALTERNATIVE-BOUNDARY\" --MULTIPART-ALTERNATIVE-BOUNDARY Content-Type: text/plain; charset=utf-8 Content-Disposition: inline This is an email example. This is text/plain content inside the mail. --MULTIPART-ALTERNATIVE-BOUNDARY-- --MULTIPART-MIXED-BOUNDARY Content-Type: application/octet-stream; Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=\"logs.txt\"" > ./mail.txt cat ./mail.txt | base64 >> ./mail.txt # end of uploaded file echo "--MULTIPART-MIXED-BOUNDARY--" >> ./mail.txt echo "sending ...." curl --url 'smtp://smtp.xxx.com:25' --ssl-reqd --mail-from $rtmp_from --mail-rcpt $rtmp_to -T './mail.txt' --insecure 

但是我试图在Docker容器中运行这个脚本。 我得到这个容器中的错误:失败连接到smtp.xxx.com:25; 没有到主机的路由。 在我的电脑中,我在/etc/ssmtp/ssmtp.conf中将mailhub改为smtp.xxx.com,所以它在本地工作。 我是新来的docker工人,不知道如何才能在docker集装箱实现这一点。 请帮忙。

在主机上执行cat /etc/resolv.conf 。 您将在您的主机上看到一些DNSconfiguration。 这需要为docker守护进程进行configuration

创build一个文件/etc/docker/daemon.json

 { "dns": ["IP1", "IP2"] } 

重新启动docker服务,然后再试一次,看看这是否适合你。

您可能在办公室networking上有自己的DNS服务器,您应该使用。 所以你需要告诉Docker守护进程它的容器应该使用哪个DNS服务器。 这就是造成这个问题的原因。 daemon.json文件可用于更改守护程序configuration。