我正在尝试使用 mailcatcher 发送电子邮件。在 docker yml 我添加了
mailcatcher:
container_name: mailcatcher
image: schickling/mailcatcher
expose:
- 1025
- 1080
ports:
- 32768:1080
- 32769:1025
并在 node.js 文件中
const transporter = nodeMailer.createTransport({
host: 'mailcatcher',
port: 1025,
ignoreTLS: true
});
const mailOptions = {
from: 'abc@gmail.com', // sender address
to: 'xyz@gmail.com', // list of receivers
subject: 'Hello ', // Subject line
text: 'Hello world?', // plain text body
html: '<b>Hello world?</b>' // html body
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log('error',error);
res.status(400).send({success: false})
} else {
res.status(200).send({success: true});
}
});
并得到回应
error Error: connect ECONNREFUSED 127.0.0.1:1025
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 1025,
command: 'CONN'
}
请提出解决方案