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
Related
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);
}
});
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}
});
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
secureConnection: false,
port: 587,
tls: {
ciphers: 'SSLv3'
},
requireTLS: true,
auth: {
user: 'mygmail',
pass: 'mypass'
}
});
var mailOptions = {
from: 'mygmail',
to: 'receiver gmail',
subject: 'Sending Email using Nodemailer',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, (error, info) => {
if (error)
return console.log(error);
console.log('Email sent: ' + info.response);
});
Above is my code for sending email through node js but I keep encounter a timeout error as below
{ Error: connect ETIMEDOUT 74.125.24.109:587
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
errno: 'ETIMEDOUT',
code: 'ECONNECTION',
syscall: 'connect',
address: '74.125.24.109',
port: 587,
command: 'CONN' }
I also tried another basic way as for the following link: https://www.w3schools.com/nodejs/nodejs_email.asp but it is not working as well.
I've already turned on allow the less secure app on my google account.
Beside of that, I also tried the method like the one in the following the link: https://jsfiddle.net/burawi/1u9m2mou/ and it is still unable to work, I generated all the client_id, client_secret, access_token, and refresh_token.
Does anyone have any latest guide or solution for sending email through node js?
Thanks
This is a network restriction issue.
Please try the same thing in your mobile network and it will work.
router.get('/mailTest', (req, res) => {
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: "mrmanagementbbsr#gmail.com", // generated ethereal user
pass: "Test#123" // generated ethereal password
}
});
let mailOptions = {
from: "mrmanagementbbsr#gmail.com", // sender address
to: 'nsubhadipta#gmail.com', // list of receivers
subject: "test subject", // Subject line
text: 'demo text'
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
res.json({ status: -1, message: 'Error Occured', error: error });
}
else {
res.json({ status: 1, message: "Email Sent" });
}
});
});
Ensure you turn on your Less secure app access, else your emails will not go through.
Then you might want to try this example:
{
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'mymail',
pass: 'mypass'
}
});
let mailOptions = {
from: 'mygmail',
to: 'receiver gmail',
subject: 'Sending Email using Nodemailer',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, (error, info)=>{
if (error) {
console.log(error);
} else {
console.log('Email sent ' + info.response');
}
});
res.json({success: 'whatever message you plan on writing'});
}
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);
});
});