I have a bug related to Nodemailer v. 6.9.3. When I launch nodeJS localhost, then this appears:
Error: connect ECONNREFUSED 127.0.0.1:465
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
errno: -111,
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 465,
command: 'CONN'
}
the code:
const nodeMailer = require('nodemailer')
const html = `
<h1>Hello World</h1>
<p>Wordked!</p>
`;
async function main() {
const transporter = nodeMailer.createTransport({
host: 'localhost',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: 'Good55555!'
}
})
const info = await transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Testing, testing, 123',
html: html,
})
console.log("Message sent: " + info.messageId)
}
main()
.catch(e => console.log(e))
I tried changing the version, rewriting the code and changing the gmail account, but nothing helped
2
Answers
Your code tells the library to try to connect to an SMTP server running on the same computer as your app, on port 465.
It tries to do this and your computer rejects the connection.
This usually means that you are not running an SMTP server on that port.
You need to provide credentials to an actual SMTP server. The fact you mentioned GMail credentials suggests you are trying to connect to GMail’s SMTP server.
GMail doesn’t run their SMTP server on your computer. You need to put in the address of their server.
The error is how you have created the transporter
Try checking out some third-party service providers for easy integration.