使用Docker的Nodemailer [英] Nodemailer with Docker
问题描述
我正试图通过register365从运行express的docker容器发送一些电子邮件。
I'm trying to send some emails from a docker container running express through register365.
这是使用的代码
export class Emailer {
transporter: nodemailer.Transporter;
constructor() {
this.transporter = nodemailer.createTransport(smtpTransport({
host: 'smtp.reg365.net',
auth: {
user: 'myuser',
pass: mypassword'
}
}));
}
public async sendEmail(to,body) {
try {
return await this.transporter.sendMail({to,from: '"TEST" <user@myuser.ie>',text: body, subject: ' WE NEED THE CONTENT AND DESIGN OF THIS EMAIL!!!!'});
}
catch(error) {
console.log('Email error');
console.dir(error);
}
}
}
如果我使用npm start运行express,一切都很好,但是如果我使用docker运行Express,它将因以下错误而失败:错误:连接已关闭
That's working all fine if I run the express with npm start but If I run it with docker it'll fail with this error Error: Connection closed
仅在使用smtp.reg.356.net时失败,如果我使用Gmail,它将运行完美
It only fails using smtp.reg.356.net, if I use Gmail it'll work perfectly
这是我正在使用的docker文件使用
This is the docker file I'm using
FROM node:8
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN npm install -g nodemon
COPY package.json /usr/src/app/
RUN npm install
COPY ./dist /usr/src/app/dist
EXPOSE 3005
EXPOSE 25
CMD [ "npm", "start" ]
非常感谢。
编辑:
根据要求,运行telnet smtp.reg365.net 25会返回以下 telnet:无法解析smtp.reg.356.net/25:名称或服务未知
在主机上输出cat /etc/resolv.conf
Output of cat /etc/resolv.conf on the host machine
domain Hitronhub.home
nameserver 89.101.160.5
nameserver 89.101.160.4
docker容器
search hitronhub.home
nameserver 127.0.0.11
options ndots:0
推荐答案
创建文件 / etc / docker / daemon .json
{
"dns": ["89.101.160.5", "89.101.160.4"]
}
重新启动docker服务,然后重试,看看是否
Restart the docker service and try again and see if this works for you.
您可能在办公室网络中,该网络具有自己的DNS服务器,您应该使用它。因此,您需要告诉Docker守护程序其容器应使用的DNS服务器。这就是造成问题的原因。 daemon.json
文件可用于更改守护程序配置。
You are probably on office network which has its own DNS servers that you should be using. So you need to tell the Docker daemon which DNS server its containers should be using. That is what is creating the issue. The daemon.json
file can be used to change the daemon configuration.
这篇关于使用Docker的Nodemailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!