I'm trying to send some emails from a docker container running express through register365.
This is the code used
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);
}
}
}
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
It only fails using smtp.reg.356.net, if I use Gmail it'll work perfectly
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" ]
Many thanks.
EDIT:
As requested, running telnet smtp.reg365.net 25 returns this telnet: could not resolve smtp.reg.356.net/25: Name or service not known
Output of cat /etc/resolv.conf on the host machine
domain Hitronhub.home
nameserver 89.101.160.5
nameserver 89.101.160.4
On the docker container
search hitronhub.home
nameserver 127.0.0.11
options ndots:0
Create a file
/etc/docker/daemon.json
Restart the docker service and try again and see if this works for you.
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.