I'm trying sending emails using node mailer but I'm getting the error
Error: connect ECONNREFUSED 127.0.0.1:587
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
errno: -4078,
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 587,
command: 'CONN'
}
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'smtp.outlook.com',
secure: false,
debug: true,
secureConnection: false,
port: 587,
auth: {
user: 'myemail#outlook.com',
pass: 'pass'
} ,
tls: {
rejectUnauthorized: true,
}
});
var mailOptions = {
from: 'myemail#outlook.com',
to: 'myemail#outlook.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
}
else {
console.log('Email sent: ' + info.response);
}
});
Related
I was trying to send an email using nodemailer in my project, I tried both gmail and hotmail here, but none work both of them are showing similar error
Error: queryA EREFUSED smtp.gmail.com
at QueryReqWrap.onresolve [as oncomplete] (node:dns:213:19) {
errno: undefined,
code: 'EDNS',
syscall: 'queryA',
hostname: 'smtp.gmail.com',
command: 'CONN'
}
The code I used is below, Can someone help me with it, i tried lot of googling on similar error and tried their solution but none worked
const nodemailer = require('nodemailer');
const transporter =await nodemailer.createTransport({
service:'hotmail',// i tried gmail, it didn't work'
port: 465,
secure:true,
auth: {
user: 'example#hotmail.com',//Tried gmail too
pass: '*********'
}
});
const mailOptions = {
from: example#hotmail.com, // tried gmail, same error
to: 'toexample#hotmail.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
SMTP informationI'm getting this error :-
Error: connect ETIMEDOUT 144.76.97.27:25
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1132:16)
{
errno: -4039,
code: 'ESOCKET',
syscall: 'connect',
address: '144.76.97.27',
port: 25,
command: 'CONN'
}
my code is:-
let transporter = nodemailer.createTransport({
host: "mail.tusharjoshi.tech",
port: 25,
secure: false, // true for 465, false for other ports
auth: {
user: "contact#tusharjoshi.tech", // generated ethereal user
pass: "mypAssword" // generated ethereal password
},
tls: {
// do not fail on invalid certs
rejectUnauthorized: false
}
});
const mailOptions = {
from: "tusharjoshi.tech",
to: "hellotusharr2318#gmail.com",
subject: `message from ${req.body.name}`,
text: `Message recieved from ${req.body.email}: and message is about: ${req.body.message}`
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
res.send("error");
} else {
console.log("send");
res.send("success");
}
});
did you check this answer? nodemailer SMTP server connection issue (Error: connect ETIMEDOUT) but it works for another system not in mine
require("dotenv").config();
"use strict";
var nodemailer = require("nodemailer");
const SMTPTransport = require("nodemailer/lib/smtp-transport");
console.log("Nach attr");
// async..await is not allowed in global scope, must use a wrapper
async function main() {
// Generate test SMTP service account from ethereal.email
// create reusable transporter object using the default SMTP transport
console.log("vor transporter");
let transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secureConnection: true, // true for 465, false for other ports
auth: {
user: 'email', // generated ethereal user
pass: 'password', // generated ethereal password
tls: {
rejectUnauthorized: false
}
},
});
transporter.verify().then(console.log).catch(console.error);
let mailOptions = {
from: 'testsender',
to: 'reciever',
subject: 'Test Mail',
text: '123456789'
};
console.log("vor transporter.send");
transporter.sendMail(mailOptions, function (err, data) {
if (err) {
console.log('Error Occurs: ', err);
} else {
console.log('Email sent!');
}
});
//console.log("Message sent: %s", info.messageId);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321#example.com>
// Preview only available when sending through an Ethereal account
//console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
main().catch(console.error);
Console output
Error Occurs: Error: connect ETIMEDOUT 64.233.166.108:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ETIMEDOUT',
code: 'ESOCKET',
syscall: 'connect',
address: '64.233.166.108',
port: 465,
command: 'CONN'
}
I have an api which sends email when a user submits data on the frontend. I can't get the nodemailer sendmail to work.
nodemailer.js -
const nodemailer = require("nodemailer");
async function sendmail(data) {
let transporter = nodemailer.createTransport({
host: "www.google.com",
port: 587,
secure: false,
auth: {
user: <my email>,
pass: <password>,
},
});
await transporter.sendMail(
{
from: data.email,
to: <my email>,
subject: "CEWA Feedback",
text: data.message,
html: "<b>Hello world?</b>",
},
(err) => {
console.log(err);
}
);
}
module.exports = sendmail;
When this function runs I get this error in the console -
Error: connect ETIMEDOUT 216.58.221.36:587
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ETIMEDOUT',
code: 'ESOCKET',
syscall: 'connect',
address: '216.58.221.36',
port: 587,
command: 'CONN'
}
Any idea what's going wrong? Thanks in advance.
can you try adding tls config to the transporter object
let transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
auth: {
user: <my email>,
pass: <password>,
},
tls: {rejectUnauthorized: false}
});
I am trying to send a simple email with nodemailer and Cloud functions for Firebase, not GMAIL I use my GoDaddy email server, but I have this error on Cloud Functions for Firebase console:
{ Error: getaddrinfo ENOTFOUND mail.square-boat.gr mail.square-boat.gr:587
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ECONNECTION',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'mail.square-boat.gr',
host: 'mail.square-boat.gr',
port: '587',
command: 'CONN' }
This is the function's code on index.js:
const mailTransport = nodemailer.createTransport({
host: 'mail.square-boat.gr',
auth: {
user: 'info#square-boat.gr',
pass: 'xxxxx!'
},
secure: false, // use TLS
port : '587'
});
exports.sendContactMessage = functions.database.ref('/emails/{pushKey}').onWrite(event => {
const snapshot = event.data;
// Only send email for new messages.
if (snapshot.previous.val() || !snapshot.val().name) {
return;
}
const val = snapshot.val();
const mailOptions = {
from: 'test#example.com',
to: 'test#example.com',
subject: `Information Request from ${val.name}`,
html: val.html
};
return mailTransport.sendMail(mailOptions).then(() => {
return console.log('Mail sent to: test#example.com')
}).catch( error => {
console.log(error);
});
});