Nodemailer SMTP Timeout Error from using ZOHO Mail Service? - node.js

I am using ZOHO mail as my email service with Nodemailer to send emails from a web app still in development. I have used the service for a while without it ever breaking and then this morning, i was testing the app, it wasn't sending out the emails and i started to get the timeout error message:
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error: queryA ETIMEOUT smtp.zoho.com
at QueryReqWrap.onresolve [as oncomplete] (node:dns:213:19) {
errno: undefined,
code: 'EDNS',
syscall: 'queryA',
hostname: 'smtp.zoho.com',
command: 'CONN'
}
Below is the controller
module.exports.mailTest = function(user) {
log(user);
let transporter = nodemailer.createTransport({
service: 'zoho',
auth: {
user: mailUser,
pass: mailPass
}
});
let userFirstName = user.name.split(' ')[0];
let mailOptions = {
from: mailUser,
to: user.email,
subject: `Mail Check`,
html: `<h2>Hi ${userFirstName}, Test Message</h2>`
}
try {
transporter.sendMail(mailOptions);
log('mail sent!');
}
catch(err) {
log(err);
throw err;
}
}
What does the error really mean and do i have to fix it from my end or is it really a problem with the smtp host?

Related

NodeMailer keeps timing out

I'm building my first node project and I'm trying to send mails to users using nodemailer and OAuth2.0. It did work last night but suddenly started timing out this morning no matter what, it runs for a few minutes and then times out without sending the mail.
This is my code so far
const nodemailer = require("nodemailer");
const sendEmail = async (email, subject, text) => {
try {
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: process.env.MAIL_USERNAME,
pass: process.env.MAIL_PASSWORD,
clientId: process.env.OAUTH_CLIENTID,
clientSecret: process.env.OAUTH_CLIENT_SECRET,
refreshToken: process.env.OAUTH_REFRESH_TOKEN
}
});
await transporter.sendMail({
from: 'user#gmail.com',
to: email,
subject: subject,
text: text,
});
console.log("email sent sucessfully");
} catch (error) {
console.log(error, "email not sent");
}
};
and I'm calling the function this way await sendEmail(email, "Password reset", link)
I get this error message after a few minutes
Error: connect ETIMEDOUT 173.194.76.108:465
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
errno: -60,
code: 'ESOCKET',
syscall: 'connect',
address: '173.194.76.108',
port: 465,
command: 'CONN'
} email not sent
I would appreciate any help as I'm really frustrated already
I fixed this by adding this to the transporter object
host: 'smtp.gmail.com',
port: 587,
secure: false,

nodemailer && mailtrap -> connect ETIMEDOUT error

I'm Working on a Dummy Project in nextjs and trying to send a reset password message to the user email using mailtrap and nodemailer but i have a problem I can't find any solution for it when I send the request this error happen
Error: connect ETIMEDOUT 18.215.44.90:2525
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
errno: -4039,
code: 'ESOCKET',
syscall: 'connect',
address: '18.215.44.90',
port: 2525,
command: 'CONN'
}
and Here's my code
import nodemailer from "nodemailer";
async function SendEmail(options) {
const transport = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: "b4f46aa8ab49eb",
pass: "100f5d80facf4d",
},
});
const message = {
from: `${process.env.SMTP_FROM_NAME} <${process.env.SMTP_FROM_EMAIL}>`,
to: options.email,
subject: options.subject,
text: options.message,
};
await transport.sendMail(message, (error, info) => {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
}
export default SendEmail;
try changing the port, another solution is to try it on another internet network, sometimes in some way, the ip provided by the provider has been blocked, that same error happened to me and my solution was to change the internet network.

Error: connect ECONNREFUSED Nodemailer Ethereal

I have an error when trying to use the example from nodemailer.
I modified it a little bit but it has all of the same core. When I try to run it I get this error:
Error: connect ECONNREFUSED 13.49.22.0:587
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
errno: -111,
code: 'ESOCKET',
syscall: 'connect',
address: '13.49.22.0',
port: 587,
command: 'CONN'
}
I have searched and I can't find any answers about this. I have heard that downgrading nodemailer's version to 4.7.0 fixes it but I have not tested this yet.
I also tested this connection to google, but it didn't work.
The function that is actually run is this:
async function nodeMailerMain() {
// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
let testAccount = await nodemailer.createTestAccount().catch((err) => console.log(err))
// create reusable transporter object using the default SMTP transport
let transporter = await nodemailer.createTransport({
host: testAccount.smtp.host,
port: testAccount.smtp.port,
secure: testAccount.smtp.secure, // true for 465, false for other ports
auth: {
user: testAccount.user, // generated ethereal user
pass: testAccount.pass, // generated ethereal password
},
})//.catch((err) => console.log(err))
console.log(testAccount.smtp.host);
console.log("successfully created transporter");
let message = {
from: 'Sender Name <sender#example.com>',
to: 'Recipient <recipient#example.com>',
subject: 'Nodemailer is unicode friendly ✔',
text: 'Hello to myself!',
html: '<p><b>Hello</b> to myself!</p>'
};
// send mail with defined transport object
transporter.sendMail(message, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Email sent: ' + info.response);
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...
});
}
It turns out that, since I was using a Gitpod workspace, the email functionality had been blocked to avoid spam-bots. See this issue on Github for more information: https://github.com/gitpod-io/gitpod/issues/8976

Nodemailer got error: 'ECONNRESET' Code:'ESOCKET'

I tried to send mail using Nodemailer by using my mail server. It work fine in localhost:8000 buy when I deploy my project to production mode It's got error: 'ECONNRESET' fyi: I use express for the backend and deploy this project on window server 2012
This is an error
error cannot sendmail: Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:201:27) {
errno: 'ECONNRESET',
code: 'ESOCKET',
syscall: 'read',
command: 'CONN'
Here is the code
const nodemailer = require('nodemailer')
let transporter = nodemailer.createTransport({
host: 'mailserver',
port: port,
tls: {
rejectUnauthorized: false
},
}
)
function Emailsender(email, link) {
let mailOption = {
from: 'xxxxxxxx#company.org',
to: `${email}`,
subject: 'News',
text: link
}
transporter.sendMail(mailOption, function (err, data) {
if (err) {
console.log('error cannot sendmail:', err)
}
else {
console.log('Email has been send')
}
})
}

How to send mail with nodemailer (node.js) by direct method?

I try to write simple mailer just to send some text (for testing purposes) with nodemailer. If I understood well it may sent a mail by smtp or direct. At first I want to sent with DIRECT method.
The next code very simple:
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({direct:true,
host: 'smtp.yandex.ru',
port: 465,
auth: {
user: 'login#yandex.ru',
pass: 'password' },
secure: true
});
var mailOptions = {
from: 'nworksheet#gmail.com',
to: 'sky-bell#mail.ru',
subject: 'Hello',
text: 'This is auto mail sending'
};
transporter.sendMail(mailOptions, function (error, info) {
if(error) {
return console.log(error);
}
console.log("Message sent "+info.response)
});
But I have the next error:
{ Error: Sending failed
at QueryReqWrap.asyncCallback [as callback] (dns.js:65:16)
at QueryReqWrap.onresolve [as oncomplete] (dns.js:216:10)
errors:
[ { Error: queryMx ENOTFOUND mail.ru
at errnoException (dns.js:28:10)
at QueryReqWrap.onresolve [as oncomplete] (dns.js:216:19)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'queryMx',
hostname: 'mail.ru' } ] }
What does it mean? How to fix it? Node not see 'mail.ru'? Why?
The best way to achieve this is
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'Yandex',
auth: {
user: 'your_yandex_email',
pass: 'your_password_for_email' },
});
var mailOptions = {
from: 'your_yandex_email',
to: 'sky-bell#mail.ru',
subject: 'Hello',
text: 'This is auto mail sending'
};
transporter.sendMail(mailOptions, function (error, info) {
if(error) {
return console.log(error);
}
console.log("Message sent "+info.response)
});
Whenever you specify the service command, it automatically sets the port and secures the email.
Also remember to put and fetch the credentials from a config file.
Looks like it can't find an MX record for mail.ru. It seems to exist however. https://toolbox.googleapps.com/apps/dig/#MX/mail.ru
Does this machine have DNS set up properly? Can you dig it from that machine?

Resources